Skip to content

Commit d43b64c

Browse files
committed
PCHR-3128: Added removal of report instances
1 parent 7e45d30 commit d43b64c

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
**/.sass-cache
44
**/node_modules
55
.DS_Store
6-
hrabsence/build
76
hrjob/build
87
bin/setup.conf
9-
hrabsence/build
108
/nbproject/private/
119
core-fork-last-commit-patched.txt
1210

hrreport/CRM/HRReport/Upgrader.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function upgrade_1403() {
236236
}
237237

238238
/**
239-
* Removes unused absence report
239+
* Removes unused absence reports and their instances
240240
*
241241
* @return bool
242242
*/
@@ -258,10 +258,34 @@ public function upgrade_1404() {
258258
civicrm_api3('OptionValue', 'delete', ['id' => $templateId]);
259259
}
260260

261-
$sql = "DELETE FROM `civicrm_managed` WHERE `entity_id` IN ('" . implode("','", $templateIds) . "')";
261+
$sql = "DELETE FROM `civicrm_managed` WHERE `entity_type` = 'ReportTemplate'";
262+
$sql .= " AND `entity_id` IN ('" . implode("','", $templateIds) . "')";
263+
262264
CRM_Core_DAO::executeQuery($sql);
263265
}
264266

267+
$this->removeReportInstances();
268+
265269
return TRUE;
266270
}
271+
272+
/**
273+
* Removes absence report instances
274+
*/
275+
private function removeReportInstances() {
276+
$reportInstances = [
277+
'CiviHR Absence Report',
278+
'CiviHR Absence Calendar Report',
279+
'CiviHR Absence Dates Report'
280+
];
281+
282+
civicrm_api3('ReportInstance', 'get', [
283+
'title' => ['IN' => $reportInstances],
284+
'api.ReportInstance.delete' => ['id' => '$value.id'],
285+
]);
286+
287+
$sql = "DELETE FROM `civicrm_managed` WHERE `entity_type` = 'ReportInstance'";
288+
$sql .= " AND name IN ('" . implode("','", $reportInstances) . "')";
289+
CRM_Core_DAO::executeQuery($sql);
290+
}
267291
}

0 commit comments

Comments
 (0)