ScheduledExecutionJob::getDataObject()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Symbiote\QueuedJobs\Jobs;
4
5
use SilverStripe\ORM\DataObject;
6
use Symbiote\QueuedJobs\Services\AbstractQueuedJob;
7
8
/**
9
 * A job that gets executed on a particular schedule. When it runs,
10
 * it will call the onScheduledExecution method on the owning
11
 * dataobject.
12
 *
13
 * @author [email protected]
14
 * @license BSD License http://silverstripe.org/bsd-license/
15
 */
16
class ScheduledExecutionJob extends AbstractQueuedJob
17
{
18
    /**
19
     * @param DataObject $dataObject
20
     * @param int $timesExecuted
21
     */
22
    public function __construct($dataObject = null, $timesExecuted = 0)
23
    {
24
        if ($dataObject) {
25
            $this->objectID = $dataObject->ID;
0 ignored issues
show
Documentation introduced by
The property objectID does not exist on object<Symbiote\QueuedJo...\ScheduledExecutionJob>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
26
            $this->objectType = $dataObject->ClassName;
0 ignored issues
show
Documentation introduced by
The property objectType does not exist on object<Symbiote\QueuedJo...\ScheduledExecutionJob>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
27
28
            // captured so we have a unique hash generated for this job
29
            $this->timesExecuted = $timesExecuted;
0 ignored issues
show
Documentation introduced by
The property timesExecuted does not exist on object<Symbiote\QueuedJo...\ScheduledExecutionJob>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
30
            $this->totalSteps = 1;
31
        }
32
    }
33
34
    /**
35
     * @return DataObject
36
     */
37
    public function getDataObject()
38
    {
39
        return DataObject::get_by_id($this->objectType, $this->objectID);
0 ignored issues
show
Documentation introduced by
The property objectType does not exist on object<Symbiote\QueuedJo...\ScheduledExecutionJob>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property objectID does not exist on object<Symbiote\QueuedJo...\ScheduledExecutionJob>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    public function getTitle()
46
    {
47
        return _t(
48
            'ScheduledExecutionJob.Title',
49
            'Scheduled execution for {title}',
50
            array('title' => $this->getDataObject()->getTitle())
51
        );
52
    }
53
54
55
    public function setup()
56
    {
57
    }
58
59
    public function process()
60
    {
61
        $object = $this->getDataObject();
62
        if ($object) {
63
            $object->onScheduledExecution();
64
65
            // figure out what our rescheduled date should be
66
            $timeStr = $object->ExecuteFree;
67
            if ($object->ExecuteEvery) {
68
                $executeInterval = $object->ExecuteInterval;
69
                if (!$executeInterval || !is_numeric($executeInterval)) {
70
                    $executeInterval = 1;
71
                }
72
                $timeStr = '+' . $executeInterval . ' ' . $object->ExecuteEvery;
73
            }
74
75
            $next = strtotime($timeStr);
76
            if ($next > time()) {
77
                // in the future
78
                $nextGen = date('Y-m-d H:i:s', $next);
79
                $nextId = singleton('Symbiote\\QueuedJobs\\Services\\QueuedJobService')->queueJob(
80
                    new ScheduledExecutionJob($object, $this->timesExecuted + 1),
0 ignored issues
show
Documentation introduced by
The property timesExecuted does not exist on object<Symbiote\QueuedJo...\ScheduledExecutionJob>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
81
                    $nextGen
82
                );
83
                $object->ScheduledJobID = $nextId;
84
                $object->write();
85
            }
86
        }
87
88
        $this->currentStep++;
89
        $this->isComplete = true;
90
    }
91
}
92