|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Contains AccountStatus class. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5.4 |
|
6
|
|
|
* |
|
7
|
|
|
* LICENSE: |
|
8
|
|
|
* This file is part of Yet Another Php Eve Api Library also know as Yapeal |
|
9
|
|
|
* which can be used to access the Eve Online API data and place it into a |
|
10
|
|
|
* database. |
|
11
|
|
|
* Copyright (C) 2016 Michael Cummings |
|
12
|
|
|
* |
|
13
|
|
|
* This program is free software: you can redistribute it and/or modify it |
|
14
|
|
|
* under the terms of the GNU Lesser General Public License as published by the |
|
15
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
|
16
|
|
|
* option) any later version. |
|
17
|
|
|
* |
|
18
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
19
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
20
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
|
21
|
|
|
* for more details. |
|
22
|
|
|
* |
|
23
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
24
|
|
|
* along with this program. If not, see |
|
25
|
|
|
* <http://www.gnu.org/licenses/>. |
|
26
|
|
|
* |
|
27
|
|
|
* You should be able to find a copy of this license in the LICENSE.md file. A |
|
28
|
|
|
* copy of the GNU GPL should also be available in the GNU-GPL.md file. |
|
29
|
|
|
* |
|
30
|
|
|
* @copyright 2016 Michael Cummings |
|
31
|
|
|
* @license http://www.gnu.org/copyleft/lesser.html GNU LGPL |
|
32
|
|
|
* @author Michael Cummings <[email protected]> |
|
33
|
|
|
*/ |
|
34
|
|
|
namespace Yapeal\EveApi\Account; |
|
35
|
|
|
|
|
36
|
|
|
use PDOException; |
|
37
|
|
|
use Yapeal\EveApi\ActiveTrait; |
|
38
|
|
|
use Yapeal\EveApi\CommonEveApiTrait; |
|
39
|
|
|
use Yapeal\Event\EveApiEventInterface; |
|
40
|
|
|
use Yapeal\Event\MediatorInterface; |
|
41
|
|
|
use Yapeal\Log\Logger; |
|
42
|
|
|
use Yapeal\Sql\PreserverTrait; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Class AccountStatus |
|
46
|
|
|
*/ |
|
47
|
|
|
class AccountStatus |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
use ActiveTrait, CommonEveApiTrait, PreserverTrait; |
|
50
|
|
|
/** |
|
51
|
|
|
* Constructor |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->mask = 33554432; |
|
56
|
|
|
} |
|
57
|
|
|
/** |
|
58
|
|
|
* @param EveApiEventInterface $event |
|
59
|
|
|
* @param string $eventName |
|
60
|
|
|
* @param MediatorInterface $yem |
|
61
|
|
|
* |
|
62
|
|
|
* @return EveApiEventInterface |
|
63
|
|
|
* @throws \DomainException |
|
64
|
|
|
* @throws \InvalidArgumentException |
|
65
|
|
|
* @throws \LogicException |
|
66
|
|
|
*/ |
|
67
|
|
|
public function preserveEveApi(EveApiEventInterface $event, $eventName, MediatorInterface $yem) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->setYem($yem); |
|
70
|
|
|
$data = $event->getData(); |
|
71
|
|
|
$xml = $data->getEveApiXml(); |
|
72
|
|
|
if (false === $xml) { |
|
73
|
|
|
return $event->setHandledSufficiently(); |
|
74
|
|
|
} |
|
75
|
|
|
$ownerID = $this->extractOwnerID($data->getEveApiArguments()); |
|
76
|
|
|
$this->getYem() |
|
77
|
|
|
->triggerLogEvent( |
|
78
|
|
|
'Yapeal.Log.log', |
|
79
|
|
|
Logger::DEBUG, |
|
80
|
|
|
$this->getReceivedEventMessage($data, $eventName, __CLASS__) |
|
81
|
|
|
); |
|
82
|
|
|
$this->getPdo() |
|
83
|
|
|
->beginTransaction(); |
|
84
|
|
|
try { |
|
85
|
|
|
$this->preserveToAccountStatus($xml, $ownerID) |
|
86
|
|
|
->preserveToMultiCharacterTraining($xml, $ownerID) |
|
87
|
|
|
->preserveToOffers($xml, $ownerID); |
|
88
|
|
|
$this->getPdo() |
|
89
|
|
|
->commit(); |
|
90
|
|
|
} catch (PDOException $exc) { |
|
91
|
|
|
$mess = 'Failed to upsert data of'; |
|
92
|
|
|
$this->getYem() |
|
93
|
|
|
->triggerLogEvent( |
|
94
|
|
|
'Yapeal.Log.log', |
|
95
|
|
|
Logger::WARNING, |
|
96
|
|
|
$this->createEveApiMessage($mess, $data), |
|
97
|
|
|
['exception' => $exc] |
|
98
|
|
|
); |
|
99
|
|
|
$this->getPdo() |
|
100
|
|
|
->rollBack(); |
|
101
|
|
|
return $event; |
|
102
|
|
|
} |
|
103
|
|
|
return $event->setHandledSufficiently(); |
|
104
|
|
|
} |
|
105
|
|
|
/** |
|
106
|
|
|
* @param string $xml |
|
107
|
|
|
* @param string $ownerID |
|
108
|
|
|
* |
|
109
|
|
|
* @return self Fluent interface. |
|
110
|
|
|
* @throws \LogicException |
|
111
|
|
|
*/ |
|
112
|
|
|
protected function preserveToAccountStatus($xml, $ownerID) |
|
113
|
|
|
{ |
|
114
|
|
|
$tableName = 'accountAccountStatus'; |
|
115
|
|
|
$sql = $this->getCsq() |
|
116
|
|
|
->getDeleteFromTableWithOwnerID($tableName, $ownerID); |
|
117
|
|
|
$this->getYem() |
|
118
|
|
|
->triggerLogEvent('Yapeal.Log.log', Logger::INFO, $sql); |
|
119
|
|
|
$this->getPdo() |
|
120
|
|
|
->exec($sql); |
|
121
|
|
|
$columnDefaults = [ |
|
122
|
|
|
'createDate' => '1970-01-01 00:00:01', |
|
123
|
|
|
'logonCount' => null, |
|
124
|
|
|
'logonMinutes' => null, |
|
125
|
|
|
'ownerID' => $ownerID, |
|
126
|
|
|
'paidUntil' => null |
|
127
|
|
|
]; |
|
128
|
|
|
$this->valuesPreserveData($xml, $columnDefaults, $tableName); |
|
129
|
|
|
return $this; |
|
130
|
|
|
} |
|
131
|
|
|
/** @noinspection PhpMissingParentCallCommonInspection */ |
|
132
|
|
|
/** |
|
133
|
|
|
* @param string $xml |
|
134
|
|
|
* @param string $ownerID |
|
135
|
|
|
* |
|
136
|
|
|
* @return self Fluent interface. |
|
137
|
|
|
* @throws \LogicException |
|
138
|
|
|
*/ |
|
139
|
|
|
protected function preserveToMultiCharacterTraining($xml, $ownerID) |
|
140
|
|
|
{ |
|
141
|
|
|
$tableName = 'accountMultiCharacterTraining'; |
|
142
|
|
|
$sql = $this->getCsq() |
|
143
|
|
|
->getDeleteFromTableWithOwnerID($tableName, $ownerID); |
|
144
|
|
|
$this->getYem() |
|
145
|
|
|
->triggerLogEvent('Yapeal.Log.log', Logger::INFO, $sql); |
|
146
|
|
|
$this->getPdo() |
|
147
|
|
|
->exec($sql); |
|
148
|
|
|
$columnDefaults = [ |
|
149
|
|
|
'ownerID' => $ownerID, |
|
150
|
|
|
'trainingEnd' => null |
|
151
|
|
|
]; |
|
152
|
|
|
$this->attributePreserveData($xml, $columnDefaults, $tableName, '//MultiCharacterTraining/row'); |
|
153
|
|
|
return $this; |
|
154
|
|
|
} |
|
155
|
|
|
/** |
|
156
|
|
|
* @param string $xml |
|
157
|
|
|
* @param string $ownerID |
|
158
|
|
|
* |
|
159
|
|
|
* @return self Fluent interface. |
|
160
|
|
|
* @throws \LogicException |
|
161
|
|
|
*/ |
|
162
|
|
|
protected function preserveToOffers($xml, $ownerID) |
|
163
|
|
|
{ |
|
164
|
|
|
$tableName = 'accountOffers'; |
|
165
|
|
|
$sql = $this->getCsq() |
|
166
|
|
|
->getDeleteFromTableWithOwnerID($tableName, $ownerID); |
|
167
|
|
|
$this->getYem() |
|
168
|
|
|
->triggerLogEvent('Yapeal.Log.log', Logger::INFO, $sql); |
|
169
|
|
|
$this->getPdo() |
|
170
|
|
|
->exec($sql); |
|
171
|
|
|
$columnDefaults = [ |
|
172
|
|
|
'from' => null, |
|
173
|
|
|
'ISK' => '0.0', |
|
174
|
|
|
'offeredDate' => '1970-01-01 00:00:01', |
|
175
|
|
|
'offerID' => null, |
|
176
|
|
|
'ownerID' => $ownerID, |
|
177
|
|
|
'to' => null |
|
178
|
|
|
]; |
|
179
|
|
|
$this->attributePreserveData($xml, $columnDefaults, $tableName, '//Offers/row'); |
|
180
|
|
|
return $this; |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|