public function _on_deleting() { $this->update_cache(false); if ($this->reportedHours > 0) { midcom_connection::set_error(MGD_ERR_HAS_DEPENDANTS); midcom::get('uimessages')->add(midcom::get('i18n')->get_string('org.openpsa.projects', 'org.openpsa.projects'), midcom::get('i18n')->get_string('task deletion now allowed because of hour reports', 'org.openpsa.projects'), 'warning'); return false; } return parent::_on_deleting(); }
/** * Deletes all invoice_hours related to the invoice */ public function _on_deleting() { if (!midcom::get('auth')->request_sudo('org.openpsa.invoices')) { debug_add('Failed to get SUDO privileges, skipping invoice hour deletion silently.', MIDCOM_LOG_ERROR); return false; } // Delete invoice_hours $tasks_to_update = array(); $qb = org_openpsa_projects_hour_report_dba::new_query_builder(); $qb->add_constraint('invoice', '=', $this->id); $hours = $qb->execute(); foreach ($hours as $hour) { $hour->invoice = 0; $hour->_skip_parent_refresh = true; $tasks_to_update[$hour->task] = true; if (!$hour->update()) { debug_add("Failed to remove invoice hour record {$hour->id}, last Midgard error was: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); } } foreach ($tasks_to_update as $id => $boolean) { try { $task = new org_openpsa_projects_task_dba($id); $task->update_cache(); } catch (midcom_error $e) { } } midcom::get('auth')->drop_sudo(); return parent::_on_deleting(); }