@@ -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