midcom_services_at_cron_clean::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 0
dl 0
loc 15
ccs 0
cts 11
cp 0
crap 6
rs 9.9332
c 0
b 0
f 0
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