~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to lib/Entity/Bandwidth.php

  • Committer: Dan Garner
  • Date: 2015-03-26 14:08:33 UTC
  • Revision ID: git-v1:70d14044444f8dc5d602b99890d59dea46d9470c
Moved web servable files to web folder

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
 * Spring Signage Ltd - http://www.springsignage.com
4
 
 * Copyright (C) 2015 Spring Signage Ltd
5
 
 * (Bandwidth.php)
6
 
 */
7
 
 
8
 
 
9
 
namespace Xibo\Entity;
10
 
use Xibo\Exception\DeadlockException;
11
 
use Xibo\Service\LogServiceInterface;
12
 
use Xibo\Storage\StorageServiceInterface;
13
 
 
14
 
 
15
 
/**
16
 
 * Class Bandwidth
17
 
 * @package Xibo\Entity
18
 
 *
19
 
 */
20
 
class Bandwidth
21
 
{
22
 
    use EntityTrait;
23
 
 
24
 
    public static $REGISTER = 1;
25
 
    public static $RF = 2;
26
 
    public static $SCHEDULE = 3;
27
 
    public static $GETFILE = 4;
28
 
    public static $GETRESOURCE = 5;
29
 
    public static $MEDIAINVENTORY = 6;
30
 
    public static $NOTIFYSTATUS = 7;
31
 
    public static $SUBMITSTATS = 8;
32
 
    public static $SUBMITLOG = 9;
33
 
    public static $BLACKLIST = 10;
34
 
    public static $SCREENSHOT = 11;
35
 
 
36
 
    public $displayId;
37
 
    public $type;
38
 
    public $size;
39
 
 
40
 
    /**
41
 
     * Entity constructor.
42
 
     * @param StorageServiceInterface $store
43
 
     * @param LogServiceInterface $log
44
 
     */
45
 
    public function __construct($store, $log)
46
 
    {
47
 
        $this->setCommonDependencies($store, $log);
48
 
    }
49
 
 
50
 
    public function save()
51
 
    {
52
 
        try {
53
 
            $this->getStore()->updateWithDeadlockLoop('
54
 
            INSERT INTO `bandwidth` (Month, Type, DisplayID, Size)
55
 
              VALUES (:month, :type, :displayId, :size)
56
 
            ON DUPLICATE KEY UPDATE Size = Size + :size2
57
 
        ', [
58
 
                'month' => strtotime(date('m') . '/02/' . date('Y') . ' 00:00:00'),
59
 
                'type' => $this->type,
60
 
                'displayId' => $this->displayId,
61
 
                'size' => $this->size,
62
 
                'size2' => $this->size
63
 
            ]);
64
 
        } catch (DeadlockException $deadlockException) {
65
 
            $this->getLog()->error('Deadlocked inserting bandwidth');
66
 
        }
67
 
    }
68
 
}
 
 
b'\\ No newline at end of file'