Commit c45ebd7d authored by BohdanDmytryshyn's avatar BohdanDmytryshyn
Browse files

Fixed install civimobileapi on civicrm 5.17 issue

parent e8b169d9
......@@ -2,8 +2,6 @@
class CRM_CiviMobileAPI_ContactSettings_Helper {
const CONTACT_SETTINGS = 'contact_settings';
/**
* Get custom fields names and IDs
*
......@@ -14,7 +12,7 @@ class CRM_CiviMobileAPI_ContactSettings_Helper {
$out = [];
$customGroupID = civicrm_api3('CustomGroup', 'get', [
'return' => "id",
'name' => self::CONTACT_SETTINGS,
'name' => CRM_CiviMobileAPI_Install_Entity_CustomGroup::CONTACT_SETTINGS,
'is_active' => 1,
]);
......@@ -24,7 +22,7 @@ class CRM_CiviMobileAPI_ContactSettings_Helper {
"id",
"name",
],
'custom_group_id' => self::CONTACT_SETTINGS,
'custom_group_id' => CRM_CiviMobileAPI_Install_Entity_CustomGroup::CONTACT_SETTINGS,
'is_active' => 1,
]);
if (isset($customFeilds["values"])) {
......@@ -37,72 +35,17 @@ class CRM_CiviMobileAPI_ContactSettings_Helper {
return $out;
}
/**
* Activates/disables custom fields
*
* @param $active
*
* @throws \CiviCRM_API3_Exception
*/
public static function setActiveFields($active) {
if (!self::isCustomGroupExist(self::CONTACT_SETTINGS)) {
return;
}
$customFields = civicrm_api3('CustomField', 'get', ['custom_group_id' => self::CONTACT_SETTINGS]);
if (isset($customFields["values"])) {
foreach ($customFields["values"] as $field) {
$field['is_active'] = $active;
civicrm_api3('CustomField', 'create', $field);
}
}
}
/**
* Activates/disables custom group
*
* @param $active
*
* @throws \CiviCRM_API3_Exception
*/
public static function setActiveGroup($active) {
$customGroupID = civicrm_api3('CustomGroup', 'get', ['name' => self::CONTACT_SETTINGS]);
if (isset($customGroupID["values"])) {
foreach ($customGroupID["values"] as $group) {
$group['is_active'] = $active;
civicrm_api3('CustomGroup', 'create', $group);
}
}
}
/**
* Deletes custom group
*
* @throws \CiviCRM_API3_Exception
*/
public static function deleteGroup() {
$customGroupID = civicrm_api3('CustomGroup', 'get', ['name' => self::CONTACT_SETTINGS]);
$customGroupID = civicrm_api3('CustomGroup', 'get', ['name' => CRM_CiviMobileAPI_Install_Entity_CustomGroup::CONTACT_SETTINGS]);
if (isset($customGroupID["values"])) {
foreach ($customGroupID["values"] as $group) {
civicrm_api3('CustomGroup', 'delete', ['id' => $group['id']]);
}
}
}
/**
* Checks if custom group exists
*
* @param $customGroupName
*
* @return bool
* @throws \CiviCRM_API3_Exception
*/
private static function isCustomGroupExist($customGroupName) {
$result = civicrm_api3('CustomGroup', 'getcount', [
'name' => $customGroupName,
]);
return $result == 1 ? TRUE : FALSE;
}
}
......@@ -18,6 +18,7 @@ class CRM_CiviMobileAPI_Install_Entity_CustomField extends CRM_CiviMobileAPI_Ins
const QR_EVENT_ID = 'civi_mobile_qr_event_id';
const QR_CODE = 'civi_mobile_qr_code';
const QR_IMAGE = 'civi_mobile_qr_image';
const BLOCKED_APP = 'blocked_app';
/**
* Params for checking Entity existence
......@@ -66,6 +67,20 @@ class CRM_CiviMobileAPI_Install_Entity_CustomField extends CRM_CiviMobileAPI_Ins
'data_type' => 'String',
'default_value' => 0,
'is_view' => 1,
],
[
'name' => self::BLOCKED_APP,
'column_name' => self::BLOCKED_APP,
'label' => ts('Blocked application'),
'custom_group_id' => CRM_CiviMobileAPI_Install_Entity_CustomGroup::CONTACT_SETTINGS,
'html_type' => 'Radio',
'data_type' => 'Boolean',
'default_value' => 0,
'is_view' => 0,
'is_searchable' => 1,
'is_required' => 0,
'is_active' => 1,
'weight' => 2,
]
];
}
......
......@@ -9,6 +9,7 @@ class CRM_CiviMobileAPI_Install_Entity_CustomGroup extends CRM_CiviMobileAPI_Ins
*/
const QR_USES = 'civi_mobile_qr_uses';
const QR_CODES = 'civi_mobile_qr_codes';
const CONTACT_SETTINGS = 'contact_settings';
/**
* Entity name
......@@ -40,6 +41,20 @@ class CRM_CiviMobileAPI_Install_Entity_CustomGroup extends CRM_CiviMobileAPI_Ins
'title' => ts('Qr codes'),
'extends' => 'Participant',
'is_public' => 0,
],
[
'name' => self::CONTACT_SETTINGS,
'title' => ts('Contact Settings'),
'extends' => 'Contact',
'is_public' => 1,
'table_name' => 'civicrm_contact_settings',
'style' => 'Inline',
'weight' => 1,
'is_active' => 1,
'collapse_display' => 1,
'collapse_adv_display' => 1,
'is_reserved' => 0,
'is_multiple' => 0
]
];
}
......
......@@ -23,16 +23,9 @@ class CRM_CiviMobileAPI_Upgrader extends CRM_CiviMobileAPI_Upgrader_Base {
}
public function upgrade_0003() {
$files = glob($this->extensionDir . '/xml/settings_install.xml');
if (is_array($files)) {
foreach ($files as $file) {
$this->executeCustomDataFileByAbsPath($file);
}
return TRUE;
} else {
return FALSE;
}
CRM_CiviMobileAPI_Install_Install::run();
return TRUE;
}
public function upgrade_0004() {
......@@ -47,19 +40,17 @@ class CRM_CiviMobileAPI_Upgrader extends CRM_CiviMobileAPI_Upgrader_Base {
public function upgrade_0005() {
try {
$this->executeSql('ALTER TABLE civicrm_contact_push_notification_messages ADD invoke_contact_id INT(10) UNSIGNED NULL');
return TRUE;
} catch (Exception $e) {
return FALSE;
}
} catch (Exception $e) {}
return TRUE;
}
public function upgrade_0006() {
try {
$this->executeSql('ALTER TABLE civicrm_contact_push_notification_messages ADD message_title varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL');
return TRUE;
} catch (Exception $e) {
return FALSE;
}
} catch (Exception $e) {}
return TRUE;
}
public function upgrade_0011() {
......@@ -82,7 +73,6 @@ class CRM_CiviMobileAPI_Upgrader extends CRM_CiviMobileAPI_Upgrader_Base {
*/
public function install() {
CRM_CiviMobileAPI_PushNotification_EventReminderHelper::createEventReminder();
CRM_CiviMobileAPI_Utils_Extension::updateSchemaVersion();
CRM_CiviMobileAPI_Install_Install::run();
Civi::settings()->set('civimobile_auto_update', 1);
......@@ -107,8 +97,6 @@ class CRM_CiviMobileAPI_Upgrader extends CRM_CiviMobileAPI_Upgrader_Base {
public function enable() {
CRM_CiviMobileAPI_Install_Install::enable();
CRM_CiviMobileAPI_PushNotification_EventReminderHelper::setEventReminderActive(1);
CRM_CiviMobileAPI_ContactSettings_Helper::setActiveFields(1);
CRM_CiviMobileAPI_ContactSettings_Helper::setActiveGroup(1);
}
/**
......
......@@ -14,8 +14,8 @@
<url desc="Support">https://agiliway.com</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2019-09-06</releaseDate>
<version>4.1.1</version>
<releaseDate>2019-09-24</releaseDate>
<version>4.1.2</version>
<develStage>stable</develStage>
<compatibility>
<ver>4.7</ver>
......
......@@ -6,6 +6,8 @@ CREATE TABLE IF NOT EXISTS `civicrm_contact_push_notification_messages` (
`entity_id` int(11) DEFAULT NULL,
`send_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`is_read` tinyint(4) DEFAULT '0',
`invoke_contact_id` INT(10) UNSIGNED NULL,
`message_title` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK_civicrm_contact_push_notification_message` (`contact_id`),
KEY `INDEX_message` (`message`),
......@@ -13,5 +15,6 @@ CREATE TABLE IF NOT EXISTS `civicrm_contact_push_notification_messages` (
KEY `INDEX_entity_record_id` (`entity_id`),
KEY `INDEX_send_date` (`send_date`),
KEY `INDEX_is_read` (`is_read`),
KEY `INDEX_invoke_contact_id` (`invoke_contact_id`),
CONSTRAINT `FK_civicrm_contact_push_notification_message` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
<?xml version="1.0" encoding="iso-8859-1" ?>
<CustomData>
<CustomGroups>
<CustomGroup>
<name>contact_settings</name>
<title>Contact Settings</title>
<table_name>civicrm_contact_settings</table_name>
<extends>Contact</extends>
<style>Inline</style>
<weight>1</weight>
<is_active>1</is_active>
<collapse_display>1</collapse_display>
<collapse_adv_display>1</collapse_adv_display>
<is_reserved>0</is_reserved>
<is_multiple>0</is_multiple>
<is_public>1</is_public>
</CustomGroup>
</CustomGroups>
<CustomFields>
<CustomField>
<name>blocked_app</name>
<column_name>blocked_app</column_name>
<label>Blocked application</label>
<custom_group_name>contact_settings</custom_group_name>
<data_type>Boolean</data_type>
<html_type>Radio</html_type>
<is_searchable>1</is_searchable>
<default_value>0</default_value>
<is_view>0</is_view>
<is_required>0</is_required>
<is_active>1</is_active>
<weight>2</weight>
</CustomField>
</CustomFields>
</CustomData>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment