1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package org.openpsa.expenses |
4
|
|
|
* @author The Midgard Project, http://www.midgard-project.org |
5
|
|
|
* @copyright The Midgard Project, http://www.midgard-project.org |
6
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* This is the interface class for org.openpsa.expenses |
11
|
|
|
* |
12
|
|
|
* @package org.openpsa.expenses |
13
|
|
|
*/ |
14
|
|
|
class org_openpsa_expenses_interface extends midcom_baseclasses_components_interface |
15
|
|
|
implements midcom_services_permalinks_resolver |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @inheritdoc |
19
|
|
|
*/ |
20
|
|
|
public function resolve_object_link(midcom_db_topic $topic, midcom_core_dbaobject $object) : ?string |
21
|
|
|
{ |
22
|
|
|
if ($object instanceof org_openpsa_expenses_hour_report_dba) { |
23
|
|
|
return "hours/edit/{$object->guid}/"; |
24
|
|
|
} |
25
|
|
|
return null; |
26
|
|
|
} |
27
|
|
|
|
28
|
19 |
|
public function _on_watched_dba_delete(midcom_core_dbaobject $object) |
29
|
|
|
{ |
30
|
19 |
|
if (!midcom::get()->auth->request_sudo($this->_component)) { |
31
|
|
|
debug_add('Failed to get SUDO privileges, skipping task cache update silently.', MIDCOM_LOG_ERROR); |
32
|
|
|
return; |
33
|
|
|
} |
34
|
|
|
|
35
|
19 |
|
$tasks_to_update = []; |
36
|
|
|
|
37
|
19 |
|
$qb = org_openpsa_expenses_hour_report_dba::new_query_builder(); |
38
|
19 |
|
$qb->add_constraint('invoice', '=', $object->id); |
39
|
19 |
|
foreach ($qb->execute() as $report) { |
40
|
3 |
|
$report->invoice = 0; |
41
|
3 |
|
$report->_skip_parent_refresh = true; |
42
|
3 |
|
$tasks_to_update[] = $report->task; |
43
|
3 |
|
if (!$report->update()) { |
44
|
|
|
debug_add("Failed to remove invoice from hour record #{$report->id}, last Midgard error was: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
19 |
|
foreach (array_unique($tasks_to_update) as $id) { |
49
|
|
|
try { |
50
|
3 |
|
org_openpsa_expenses_hour_report_dba::update_cache(new org_openpsa_projects_task_dba($id)); |
51
|
|
|
} catch (midcom_error $e) { |
52
|
|
|
$e->log(); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
19 |
|
midcom::get()->auth->drop_sudo(); |
57
|
19 |
|
} |
58
|
|
|
} |
59
|
|
|
|