Issues (186)

includes/DataObjects/SiteNotice.php (1 issue)

Labels
Severity
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 * ACC Development Team. Please see team.json for a list of contributors.     *
5
 *                                                                            *
6
 * This is free and unencumbered software released into the public domain.    *
7
 * Please see LICENSE.md for the full licencing statement.                    *
8
 ******************************************************************************/
9
10
namespace Waca\DataObjects;
11
12
use Exception;
13
use Waca\DataObject;
14
use Waca\Exceptions\OptimisticLockFailedException;
15
use Waca\PdoDatabase;
16
17
/**
18
 * Interface data object
19
 *
20
 * Interface messages for those messages which are not templates.
21
 */
22
class SiteNotice extends DataObject
23
{
24
    /** @var string */
25
    private $content;
26
27
    /**
28
     * Get a message.
29
     *
30
     * @param PdoDatabase $database
31
     *
32
     * @return string The content for display
33
     */
34
    public static function get(PdoDatabase $database)
35
    {
36
        /** @var SiteNotice $message */
37
        $message = self::getById(1, $database);
38
39
        return $message->getContent();
40
    }
41
42
    /**
43
     * Saves the object
44
     * @throws Exception
45
     */
46
    public function save()
47
    {
48
        if ($this->isNew()) {
49
            // insert
50
            throw new Exception('Not allowed to create new site notice object');
51
        }
52
        else {
53
            // update
54
            $statement = $this->dbObject->prepare(<<<SQL
55
UPDATE sitenotice
56
SET content = :content, updateversion = updateversion + 1
57
WHERE updateversion = :updateversion;
58
SQL
59
            );
60
            $statement->bindValue(':updateversion', $this->updateversion);
61
62
            $statement->bindValue(':content', $this->content);
63
64
            if (!$statement->execute()) {
65
                throw new Exception($statement->errorInfo());
0 ignored issues
show
$statement->errorInfo() of type array is incompatible with the type string expected by parameter $message of Exception::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
                throw new Exception(/** @scrutinizer ignore-type */ $statement->errorInfo());
Loading history...
66
            }
67
68
            if ($statement->rowCount() !== 1) {
69
                throw new OptimisticLockFailedException();
70
            }
71
72
            $this->updateversion++;
73
        }
74
    }
75
76
    /**
77
     * Gets the content of the message
78
     * @return string
79
     */
80
    public function getContent()
81
    {
82
        return $this->content;
83
    }
84
85
    /**
86
     * Sets the content of the message
87
     *
88
     * @param string $content
89
     */
90
    public function setContent($content)
91
    {
92
        $this->content = $content;
93
    }
94
}
95