Commit 471b084e authored by BohdanDmytryshyn's avatar BohdanDmytryshyn
Browse files

Add 'Civimobile clean old push notification messages' Scheduled Job.

parent 42d7dcb2
......@@ -2,6 +2,11 @@
class CRM_CiviMobileAPI_BAO_PushNotificationMessages extends CRM_CiviMobileAPI_DAO_PushNotificationMessages {
/**
* Life time
*/
const LIFE_TIME_IN_DAYS = 90;
/**
* Adds params to Push Notification Messages table
*
......@@ -24,7 +29,7 @@ class CRM_CiviMobileAPI_BAO_PushNotificationMessages extends CRM_CiviMobileAPI_D
*/
public static function &create(&$params) {
$transaction = new self();
if (!empty($params['id'])) {
CRM_Utils_Hook::pre('edit', self::getEntityName(), $params['id'], $params);
}
......@@ -128,7 +133,7 @@ class CRM_CiviMobileAPI_BAO_PushNotificationMessages extends CRM_CiviMobileAPI_D
/**
* Gets notifications by params
*
*
* @param $params
*
* @return array|bool
......@@ -143,7 +148,7 @@ class CRM_CiviMobileAPI_BAO_PushNotificationMessages extends CRM_CiviMobileAPI_D
}
$query->orderBy($params['sort'] . ' ' . $params['direction']);
if (isset($params['limit'])) {
$offset = isset($params['offset']) ? $params['offset'] : 0;
$query->limit($params['limit'], $offset);
......@@ -155,4 +160,20 @@ class CRM_CiviMobileAPI_BAO_PushNotificationMessages extends CRM_CiviMobileAPI_D
return !empty($data) ? $data : FALSE;
}
/**
* Deletes older than count of days
*
* @param $day
*/
public static function deleteOlderThan($day) {
$query = '
DELETE FROM civicrm_contact_push_notification_messages
WHERE send_date < NOW() - INTERVAL %1 DAY;
';
CRM_Core_DAO::singleValueQuery($query, [
1 => [$day, 'Integer']
]);
}
}
......@@ -77,7 +77,7 @@ abstract class CRM_CiviMobileAPI_Install_Entity_EntityBase implements CRM_CiviM
*
* @return bool|int
*/
private function getId($entityParam) {
protected function getId($entityParam) {
$searchParam = [];
foreach ($this->entitySearchParamNameList as $nameParam) {
$searchParam[$nameParam] = $entityParam[$nameParam];
......
......@@ -9,6 +9,7 @@ class CRM_CiviMobileAPI_Install_Install {
(new CRM_CiviMobileAPI_Install_Entity_CustomGroup())->install();
(new CRM_CiviMobileAPI_Install_Entity_CustomField())->install();
(new CRM_CiviMobileAPI_Install_Entity_UpdateMessageTemplate())->install();
(new CRM_CiviMobileAPI_Install_Entity_Job())->install();
}
/**
......@@ -16,6 +17,7 @@ class CRM_CiviMobileAPI_Install_Install {
*/
public static function disable() {
(new CRM_CiviMobileAPI_Install_Entity_CustomGroup())->disableAll();
(new CRM_CiviMobileAPI_Install_Entity_Job())->disableAll();
}
/**
......@@ -23,6 +25,7 @@ class CRM_CiviMobileAPI_Install_Install {
*/
public static function enable() {
(new CRM_CiviMobileAPI_Install_Entity_CustomGroup())->enableAll();
(new CRM_CiviMobileAPI_Install_Entity_Job())->enableAll();
}
}
......@@ -66,6 +66,12 @@ class CRM_CiviMobileAPI_Upgrader extends CRM_CiviMobileAPI_Upgrader_Base {
return TRUE;
}
public function upgrade_0013() {
CRM_CiviMobileAPI_Install_Install::run();
return TRUE;
}
/**
* Installs scheduled job
*
......
......@@ -8,22 +8,22 @@
* @return array
*/
function civicrm_api3_push_notification_messages_get($params) {
if (isset($params['options']['limit'])) {
$params['limit'] = $params['options']['limit'];
$params['offset'] = isset($params['options']['offset']) ? $params['options']['offset'] : 0;
}
if (!isset($params['options']['sort'])) {
$params['sort'] = 'id';
} else {
$params['sort'] = $params['options']['sort'];
}
if (!isset($params['direction'])) {
$params['direction'] = 'DESC';
}
$messages = CRM_CiviMobileAPI_BAO_PushNotificationMessages::getNotifications($params);
return civicrm_api3_create_success($messages, $params);
......@@ -51,3 +51,32 @@ function _civicrm_api3_push_notification_messages_get_spec(&$params) {
];
}
/**
* Clears old Push notification messages
*
* @param array $params
*
* @return array
*/
function civicrm_api3_push_notification_messages_clear_old($params) {
$countOfDays = (isset($params['count_of_day'])) ? (int) $params['count_of_day'] : CRM_CiviMobileAPI_BAO_PushNotificationMessages::LIFE_TIME_IN_DAYS;
CRM_CiviMobileAPI_BAO_PushNotificationMessages::deleteOlderThan($countOfDays);
return civicrm_api3_create_success(['message' => 'Push notification messages older than ' . $countOfDays . ' days was deleted.']);
}
/**
* Adjust Metadata
*
* The metadata is used for setting defaults, documentation & validation
* @param array $params array or parameters determined by getfields
*/
function _civicrm_api3_push_notification_messages_clear_old_spec(&$params) {
$params['count_of_day'] = [
'title' => 'Count of days',
'description' => ts('Deletes "Push notification messages" older than this param. Default 90.'),
'api.required' => 0,
'type' => CRM_Utils_Type::T_INT
];
}
......@@ -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-11-12</releaseDate>
<version>4.2</version>
<releaseDate>2019-11-26</releaseDate>
<version>4.2.1</version>
<develStage>stable</develStage>
<compatibility>
<ver>4.7</ver>
......
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