midcom_services_at_cron_clean   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 20
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 15 2
1
<?php
2
/**
3
 * @package midcom.services.at
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
 * Clears dangling "running"/failed entries
11
 *
12
 * @package midcom.services.at
13
 */
14
class midcom_services_at_cron_clean extends midcom_baseclasses_components_cron_handler
15
{
16
    /**
17
     * Loads all entries that need to be processed and processes them.
18
     */
19
    public function execute()
20
    {
21
        $qb = midcom_services_at_entry_dba::new_query_builder();
22
        // (to be) start(ed) AND last touched over two days ago
23
        $qb->add_constraint('start', '<=', time() - 3600 * 24 * 2);
24
        $qb->add_constraint('metadata.revised', '<=', date('Y-m-d H:i:s', time() - 3600 * 24 * 2));
25
        $qb->add_constraint('status', '>=', midcom_services_at_entry_dba::RUNNING);
26
27
        midcom::get()->auth->request_sudo($this->_component);
28
        foreach ($qb->execute() as $entry) {
29
            debug_add("Deleting dangling entry #{$entry->id}\n", MIDCOM_LOG_INFO);
30
            debug_print_r("Entry #{$entry->id} dump: ", $entry);
31
            $entry->delete();
32
        }
33
        midcom::get()->auth->drop_sudo();
34
    }
35
}
36