Completed
Push — master ( fd92f5...bc11d0 )
by Nick
06:37
created

GlossaryEditQueue   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 69
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B approve() 0 65 6
1
<?php
2
/**
3
 * GlossaryEditQueue Class
4
 *
5
 * @package TheyWorkForYou
6
 */
7
8
namespace MySociety\TheyWorkForYou;
9
10
/**
11
 * Glossary Edit Queue
12
 */
13
14
// Glossary overrides
15
class GlossaryEditQueue extends EditQueue {
16
17
    public function approve($data) {
18
    // Approve items for inclusion
19
    // Create new epobject and update the editqueue
20
21
        global $THEUSER;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
22
23
        // We need a list of editqueue items to play with
24
        $this->get_pending();
25
        if (!isset($this->pending)) {
26
            return false;
27
        }
28
        $timestamp = date('Y-m-d H:i:s', time());
29
30
        foreach ($data['approvals'] as $approval_id) {
31
            // create a new epobject
32
            //      title VARCHAR(255),
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
33
            //      body TEXT,
34
            //      type INTEGER,
35
            //      created DATETIME,
36
            //      modified DATETIME,
37
            /*print "<pre>";
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
38
            print_r($data);
39
            print "</pre>";*/
40
            // Check to see that we actually have something to approve
41
            if (!isset($this->pending[$approval_id])) {
42
                break;
43
            }
44
            $q = $this->db->query("INSERT INTO glossary
45
                            (title, body, type, created, visible)
46
                            VALUES
47
                            ('" . addslashes($this->pending[$approval_id]['title']) . "',
48
                            '" . addslashes($this->pending[$approval_id]['body']) . "',
49
                            '" . $data['epobject_type'] . "',
50
                            '" . $timestamp . "',
51
                            1);");
52
53
            // If that didn't work we can't go any further...
54
            if (!$q->success()) {
55
                print "glossary trouble";
56
                return false;
57
            }
58
            $this->current_epobject_id = $q->insert_id();
59
60
            // Then finally update the editqueue with
61
            // the new epobject id and approval details.
62
            $q = $this->db->query("UPDATE editqueue
63
                            SET
64
                            glossary_id='" .  $this->current_epobject_id. "',
65
                            editor_id='" . addslashes($THEUSER->user_id()) . "',
66
                            approved='1',
67
                            decided='" . $timestamp . "'
68
                            WHERE edit_id=" . $approval_id . ";");
69
            if (!$q->success()) {
70
                break;
71
            }
72
            else {
73
                // Scrub that one from the list of pending items
74
                unset ($this->pending[$approval_id]);
75
            }
76
        }
77
78
        $this->update_pending_count();
79
80
        return true;
81
    }
82
83
}
84