@@ -19,7 +19,7 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | public function register() |
| 21 | 21 | { |
| 22 | - $this->getContainer()->add('Ramsey\Uuid\Uuid', function () { |
|
| 22 | + $this->getContainer()->add('Ramsey\Uuid\Uuid', function() { |
|
| 23 | 23 | $uuid = Uuid::Uuid4(); |
| 24 | 24 | return $uuid; |
| 25 | 25 | }); |
@@ -1,8 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | use GuzzleHttp\Client; |
| 4 | -use GuzzleHttp\Psr7\Request; |
|
| 5 | -use GuzzleHttp\Psr7\Response; |
|
| 6 | 4 | |
| 7 | 5 | class AlertControllerTest extends \PHPUnit_Framework_TestCase |
| 8 | 6 | { |
@@ -342,7 +342,7 @@ |
||
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | if (! in_array($id, $filters)) { |
| 345 | - throw new InvalidArgumentException("Unrecognized {$mode}. Please check the IDs you sent."); |
|
| 345 | + throw new InvalidArgumentException("unrecognized {$mode}. Please check the IDs you sent."); |
|
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | 348 | |
@@ -98,8 +98,6 @@ discard block |
||
| 98 | 98 | * @param string $kind The kind of data we wish to return |
| 99 | 99 | * @param array $data The data itself |
| 100 | 100 | * @param \League\Fractal\TransformerAbstract $callback The transformer class to call |
| 101 | - * @param \Psr\Http\Message\ServerRequestInterface $request The request itself |
|
| 102 | - * @param \Psr\Http\Message\ResponseInterface $response The response object to eventually call |
|
| 103 | 101 | * |
| 104 | 102 | * @return \Psr\Http\Message\ResponseInterface |
| 105 | 103 | */ |
@@ -122,9 +120,8 @@ discard block |
||
| 122 | 120 | * |
| 123 | 121 | * @param array $item The item to transform |
| 124 | 122 | * @param \League\Fractal\TransformerAbstract $transformer The Transformer to pass through to Fractal |
| 125 | - * @param \Psr\Http\Message\ResponseInterface $response The client's response |
|
| 126 | 123 | * |
| 127 | - * @return array |
|
| 124 | + * @return ResponseInterface |
|
| 128 | 125 | */ |
| 129 | 126 | protected function respondWithItem($item, $transformer) |
| 130 | 127 | { |
@@ -152,9 +149,8 @@ discard block |
||
| 152 | 149 | * |
| 153 | 150 | * @param array $collection The collection to transform |
| 154 | 151 | * @param \League\Fractal\TransformerAbstract $transformer The Transformer to pass through to Fractal |
| 155 | - * @param \Psr\Http\Message\ResponseInterface $response The client's response |
|
| 156 | 152 | * |
| 157 | - * @return array |
|
| 153 | + * @return ResponseInterface |
|
| 158 | 154 | */ |
| 159 | 155 | protected function respondWithCollection($collection, $transformer) |
| 160 | 156 | { |
@@ -180,7 +176,6 @@ discard block |
||
| 180 | 176 | /** |
| 181 | 177 | * The final step where the formatted array is now sent back as a response in JSON form |
| 182 | 178 | * |
| 183 | - * @param \Psr\Http\Message\ResponseInterface $response |
|
| 184 | 179 | * @param array $array |
| 185 | 180 | * |
| 186 | 181 | * @return \Psr\Http\Message\ResponseInterface |
@@ -210,11 +205,10 @@ discard block |
||
| 210 | 205 | /** |
| 211 | 206 | * Responds gracefully with an error. |
| 212 | 207 | * |
| 213 | - * @param \Psr\Http\Message\ResponseInterface $response |
|
| 214 | 208 | * @param string $message Response message to put in the error |
| 215 | 209 | * @param int $errorCode Error code to set |
| 216 | 210 | * |
| 217 | - * @return array |
|
| 211 | + * @return ResponseInterface |
|
| 218 | 212 | */ |
| 219 | 213 | protected function respondWithError($message, $errorCode) |
| 220 | 214 | { |
@@ -238,10 +232,9 @@ discard block |
||
| 238 | 232 | /** |
| 239 | 233 | * Generates a response with a 404 HTTP error and a given message. |
| 240 | 234 | * |
| 241 | - * @param \Psr\Http\Message\ResponseInterface $response |
|
| 242 | 235 | * @param string $message |
| 243 | 236 | * |
| 244 | - * @return void |
|
| 237 | + * @return ResponseInterface |
|
| 245 | 238 | */ |
| 246 | 239 | public function errorEmpty($message = 'No data / Empty') |
| 247 | 240 | { |
@@ -252,10 +245,9 @@ discard block |
||
| 252 | 245 | /** |
| 253 | 246 | * Generates a Response with a 403 HTTP header and a given message. |
| 254 | 247 | * |
| 255 | - * @param \Psr\Http\Message\ResponseInterface $response |
|
| 256 | 248 | * @param string $message |
| 257 | 249 | * |
| 258 | - * @return void |
|
| 250 | + * @return ResponseInterface |
|
| 259 | 251 | */ |
| 260 | 252 | public function errorForbidden($message = 'Forbidden') |
| 261 | 253 | { |
@@ -266,10 +258,9 @@ discard block |
||
| 266 | 258 | /** |
| 267 | 259 | * Generates a Response with a 500 HTTP header and a given message. |
| 268 | 260 | * |
| 269 | - * @param \Psr\Http\Message\ResponseInterface $response |
|
| 270 | 261 | * @param string $message |
| 271 | 262 | * |
| 272 | - * @return void |
|
| 263 | + * @return ResponseInterface |
|
| 273 | 264 | */ |
| 274 | 265 | public function errorInternalError($message = 'Internal Error') |
| 275 | 266 | { |
@@ -280,10 +271,9 @@ discard block |
||
| 280 | 271 | /** |
| 281 | 272 | * Generates a Response with a 404 HTTP header and a given message. |
| 282 | 273 | * |
| 283 | - * @param \Psr\Http\Message\ResponseInterface $response |
|
| 284 | 274 | * @param string $message |
| 285 | 275 | * |
| 286 | - * @return void |
|
| 276 | + * @return ResponseInterface |
|
| 287 | 277 | */ |
| 288 | 278 | public function errorNotFound($message = 'Resource Not Found') |
| 289 | 279 | { |
@@ -294,10 +284,9 @@ discard block |
||
| 294 | 284 | /** |
| 295 | 285 | * Generates a Response with a 401 HTTP header and a given message. |
| 296 | 286 | * |
| 297 | - * @param \Psr\Http\Message\ResponseInterface $response |
|
| 298 | 287 | * @param string $message |
| 299 | 288 | * |
| 300 | - * @return void |
|
| 289 | + * @return ResponseInterface |
|
| 301 | 290 | */ |
| 302 | 291 | public function errorUnauthorized($message = 'Unauthorized') |
| 303 | 292 | { |
@@ -308,7 +297,6 @@ discard block |
||
| 308 | 297 | /** |
| 309 | 298 | * Generates a Response with a 400 HTTP header and a given message. |
| 310 | 299 | * |
| 311 | - * @param \Psr\Http\Message\ResponseInterface $response |
|
| 312 | 300 | * @param string $message |
| 313 | 301 | * |
| 314 | 302 | * @return \Psr\Http\Message\ResponseInterface |
@@ -322,7 +310,6 @@ discard block |
||
| 322 | 310 | /** |
| 323 | 311 | * Reads any requested includes and adds them to the item / collection |
| 324 | 312 | * |
| 325 | - * @param Psr\Http\Message\ServerRequestInterface $request |
|
| 326 | 313 | * |
| 327 | 314 | * @return void |
| 328 | 315 | */ |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | */ |
| 329 | 329 | public function getIncludesFromRequest() |
| 330 | 330 | { |
| 331 | - if (! empty($_GET['embed'])) { |
|
| 331 | + if (!empty($_GET['embed'])) { |
|
| 332 | 332 | $this->fractal->parseIncludes($_GET['embed']); |
| 333 | 333 | } |
| 334 | 334 | } |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | throw new \Exception(); |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | - if (! $time) { |
|
| 411 | + if (!$time) { |
|
| 412 | 412 | $time = 3600 * 24; // 1 day |
| 413 | 413 | } |
| 414 | 414 | |
@@ -432,14 +432,14 @@ discard block |
||
| 432 | 432 | $numericals = ['servers', 'zones']; |
| 433 | 433 | $strings = ['factions', 'brackets']; |
| 434 | 434 | |
| 435 | - if (! empty($queryString)) { |
|
| 435 | + if (!empty($queryString)) { |
|
| 436 | 436 | $check = explode(',', $queryString); |
| 437 | 437 | |
| 438 | 438 | // Run a check on the IDs provided to make sure they're valid and no naughty things are being passed |
| 439 | 439 | foreach ($check as $id) { |
| 440 | 440 | // If the query string should contain only numbers |
| 441 | 441 | if (in_array($mode, $numericals)) { |
| 442 | - if (! is_numeric($id)) { |
|
| 442 | + if (!is_numeric($id)) { |
|
| 443 | 443 | throw new InvalidArgumentException("Non numerical ID detected. Only numerical IDs are accepted with this request."); |
| 444 | 444 | } |
| 445 | 445 | } |
@@ -449,14 +449,14 @@ discard block |
||
| 449 | 449 | } |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | - if (! in_array($id, $filters)) { |
|
| 452 | + if (!in_array($id, $filters)) { |
|
| 453 | 453 | throw new InvalidArgumentException("Unrecognized {$mode}. Please check the IDs you sent."); |
| 454 | 454 | } |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | // Format into strings comma seperated for SQL |
| 458 | 458 | if (in_array($mode, $strings)) { |
| 459 | - $queryString = "'" . implode("','", $check) . "'"; |
|
| 459 | + $queryString = "'".implode("','", $check)."'"; |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | return $queryString; |
@@ -465,7 +465,7 @@ discard block |
||
| 465 | 465 | $return = implode(',', $filters); |
| 466 | 466 | |
| 467 | 467 | if (in_array($mode, $strings)) { |
| 468 | - $return = "'" . implode("','", $filters) . "'"; |
|
| 468 | + $return = "'".implode("','", $filters)."'"; |
|
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | // If no string was provided, returns all data encoded as a comma seperated string |
@@ -32,8 +32,8 @@ discard block |
||
| 32 | 32 | /** |
| 33 | 33 | * Execution |
| 34 | 34 | * |
| 35 | - * @param Symfony\Component\Console\Input\InputInterface $input |
|
| 36 | - * @param Symfony\Component\Console\Output\OutputInterface $output |
|
| 35 | + * @param InputInterface $input |
|
| 36 | + * @param OutputInterface $output |
|
| 37 | 37 | * |
| 38 | 38 | * @return void |
| 39 | 39 | */ |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * Checks for alerts to be archived then runs routing against said alerts |
| 49 | 49 | * |
| 50 | - * @param Symfony\Component\Console\Output\OutputInterface $output |
|
| 50 | + * @param OutputInterface $output |
|
| 51 | 51 | * |
| 52 | 52 | * @return void |
| 53 | 53 | */ |
@@ -121,8 +121,8 @@ discard block |
||
| 121 | 121 | * Execution of routine |
| 122 | 122 | * |
| 123 | 123 | * @param array $alert |
| 124 | - * @param array $tables |
|
| 125 | - * @param Symfony\Component\Console\Output\OutputInterface $output |
|
| 124 | + * @param string[] $tables |
|
| 125 | + * @param OutputInterface $output |
|
| 126 | 126 | * |
| 127 | 127 | * @return void |
| 128 | 128 | */ |
@@ -7,7 +7,6 @@ |
||
| 7 | 7 | use Symfony\Component\Console\Command\Command; |
| 8 | 8 | use Symfony\Component\Console\Input\InputArgument; |
| 9 | 9 | use Symfony\Component\Console\Input\InputInterface; |
| 10 | -use Symfony\Component\Console\Input\InputOption; |
|
| 11 | 10 | use Symfony\Component\Console\Output\OutputInterface; |
| 12 | 11 | |
| 13 | 12 | class ArchiveCommand extends BaseCommand |
@@ -61,11 +61,11 @@ discard block |
||
| 61 | 61 | $query->where('ResultStartTime < ?', $obj->format('U')); |
| 62 | 62 | $query->where('Archived = 0'); |
| 63 | 63 | |
| 64 | - if (! empty($input->getArgument('start'))) { |
|
| 64 | + if (!empty($input->getArgument('start'))) { |
|
| 65 | 65 | $query->where('ResultID >= ?', $input->getArgument('start')); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - if (! empty($input->getArgument('process'))) { |
|
| 68 | + if (!empty($input->getArgument('process'))) { |
|
| 69 | 69 | $query->where('ResultID <= ?', $input->getArgument('process')); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | 'ws_xp' |
| 91 | 91 | ]; |
| 92 | 92 | |
| 93 | - for ($i=0; $i < $count; $i++) { |
|
| 93 | + for ($i = 0; $i < $count; $i++) { |
|
| 94 | 94 | $this->archive($alerts[$i], $tables, $output); |
| 95 | 95 | |
| 96 | 96 | $per = ($i / $count) * 100; |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | $this->guzzle->request( |
| 112 | 112 | 'POST', |
| 113 | 113 | 'https://hooks.slack.com/services/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', |
| 114 | - ['json' => $payload ] |
|
| 114 | + ['json' => $payload] |
|
| 115 | 115 | ); |
| 116 | 116 | |
| 117 | 117 | $output->writeln("Archived {$records} records!"); |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | $this->dbArchive->beginTransaction(); |
| 134 | 134 | |
| 135 | 135 | // Get all data and insert it into the archive DB |
| 136 | - foreach($tables as $table) { |
|
| 136 | + foreach ($tables as $table) { |
|
| 137 | 137 | $output->writeln("Alert #{$alert['ResultID']} - Table: {$table}"); |
| 138 | 138 | |
| 139 | 139 | $sql = "SELECT * FROM {$table} WHERE resultID = :result"; |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | $values = rtrim($values, ','); |
| 158 | - $sql = "INSERT INTO {$table} ({$cols}) VALUES {$values}"; |
|
| 158 | + $sql = "INSERT INTO {$table} ({$cols}) VALUES {$values}"; |
|
| 159 | 159 | |
| 160 | 160 | $this->dbArchive->exec($sql); |
| 161 | 161 | } |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | $this->db->beginTransaction(); |
| 176 | 176 | |
| 177 | 177 | // Loop through all tables and delete the alert's data from the DB |
| 178 | - foreach($tables as $table) { |
|
| 178 | + foreach ($tables as $table) { |
|
| 179 | 179 | $sql = "DELETE FROM {$table} WHERE resultID = :result"; |
| 180 | 180 | $stm = $this->db->prepare($sql); |
| 181 | 181 | $stm->execute(['result' => $alert['ResultID']]); |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | public function buildCols($row) |
| 208 | 208 | { |
| 209 | 209 | $keys = []; |
| 210 | - foreach($row as $key => $val) { |
|
| 210 | + foreach ($row as $key => $val) { |
|
| 211 | 211 | $keys[] = (string) $key; |
| 212 | 212 | } |
| 213 | 213 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | public function buildValues($row) |
| 225 | 225 | { |
| 226 | 226 | $values = []; |
| 227 | - foreach($row as $key => $val) { |
|
| 227 | + foreach ($row as $key => $val) { |
|
| 228 | 228 | $val = str_replace("'", '', $val); // Remove any apostophies from char names |
| 229 | 229 | $values[] = $val; |
| 230 | 230 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | $alerts = $this->alertRepo->fireStatementAndReturn($query); |
| 73 | 73 | $count = count($alerts); |
| 74 | 74 | |
| 75 | - $output->writeln("Detected {$count} alerts to be archived"); |
|
| 75 | + $output->writeln("detected {$count} alerts to be archived"); |
|
| 76 | 76 | |
| 77 | 77 | if ($count > 0) { |
| 78 | 78 | $tables = [ |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | ['json' => $payload ] |
| 115 | 115 | ); |
| 116 | 116 | |
| 117 | - $output->writeln("Archived {$records} records!"); |
|
| 117 | + $output->writeln("archived {$records} records!"); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | $this->recordsArchived += $stm->rowCount(); |
| 184 | 184 | $records += $stm->rowCount(); |
| 185 | 185 | |
| 186 | - $output->writeln("Archived {$stm->rowCount()} from Alert #{$alert['ResultID']} - Table {$table}"); |
|
| 186 | + $output->writeln("archived {$stm->rowCount()} from Alert #{$alert['ResultID']} - Table {$table}"); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | $this->db->commit(); |
@@ -49,6 +49,10 @@ discard block |
||
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | + /** |
|
| 53 | + * @param OutputInterface $output |
|
| 54 | + * @param boolean $force |
|
| 55 | + */ |
|
| 52 | 56 | public function processAlert($id, $output, $force = null) |
| 53 | 57 | { |
| 54 | 58 | $alert = $this->alertRepo->readSingleById($id, 'primary', true); |
@@ -183,6 +187,12 @@ discard block |
||
| 183 | 187 | ); |
| 184 | 188 | } |
| 185 | 189 | |
| 190 | + /** |
|
| 191 | + * @param string $table |
|
| 192 | + * @param string $totalsTable |
|
| 193 | + * @param string $filter |
|
| 194 | + * @param string[] $groupBy |
|
| 195 | + */ |
|
| 186 | 196 | protected function runProcess( |
| 187 | 197 | $id, |
| 188 | 198 | array $cols, |
@@ -18,8 +18,8 @@ |
||
| 18 | 18 | { |
| 19 | 19 | parent::configure(); // See BaseCommand.php |
| 20 | 20 | $this->setName('DeleteAlert') |
| 21 | - ->setDescription('Deletes an alert and corrects totals') |
|
| 22 | - ->addArgument( |
|
| 21 | + ->setDescription('Deletes an alert and corrects totals') |
|
| 22 | + ->addArgument( |
|
| 23 | 23 | 'alert', |
| 24 | 24 | InputArgument::REQUIRED, |
| 25 | 25 | 'Alert ID to process' |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | ) { |
| 195 | 195 | // Check each cols to make sure we handle SUM(BLAH) AS BLAH issues |
| 196 | 196 | |
| 197 | - foreach($cols as $key => $col) { |
|
| 197 | + foreach ($cols as $key => $col) { |
|
| 198 | 198 | if (strpos($col, 'AS ') !== false) { |
| 199 | 199 | $pos = strrpos($col, 'AS ') + 3; // Plus 3 for "AS " |
| 200 | 200 | $len = strlen($col); |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | $query->from($table); |
| 211 | 211 | $query->where('resultID = ?', $id); |
| 212 | 212 | |
| 213 | - if (! empty($groupBy)) { |
|
| 213 | + if (!empty($groupBy)) { |
|
| 214 | 214 | $query->groupBy($groupBy); |
| 215 | 215 | } |
| 216 | 216 | |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | $update->table($totalsTable); |
| 227 | 227 | $update->where("{$filter} = ?", $row->$filter); |
| 228 | 228 | |
| 229 | - foreach($fields as $field) { |
|
| 229 | + foreach ($fields as $field) { |
|
| 230 | 230 | $update->set($field, "{$field} - {$row->$field}"); |
| 231 | 231 | } |
| 232 | 232 | |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | |
| 240 | 240 | protected function deleteAllFromTables(array $tables, $id, OutputInterface $output) |
| 241 | 241 | { |
| 242 | - foreach($tables as $table) { |
|
| 242 | + foreach ($tables as $table) { |
|
| 243 | 243 | $delete = $this->auraFactory->newDelete(); |
| 244 | 244 | $delete->from($table); |
| 245 | 245 | $delete->where('resultID = ?', $id); |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $alert = $this->alertRepo->readSingleById($id, 'primary', true); |
| 55 | 55 | |
| 56 | 56 | if (empty($force) && empty($id)) { |
| 57 | - $output->writeln("ALERT {$id} DOES NOT EXIST!"); |
|
| 57 | + $output->writeln("alert {$id} DOES NOT EXIST!"); |
|
| 58 | 58 | return false; |
| 59 | 59 | } |
| 60 | 60 | |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | $this->deleteAlert($id); |
| 100 | 100 | |
| 101 | 101 | if ($this->verbose === 1) { |
| 102 | - $output->writeln("Alert {$id} successfully deleted!"); |
|
| 102 | + $output->writeln("alert {$id} successfully deleted!"); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | return true; |
@@ -89,6 +89,10 @@ |
||
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | + /** |
|
| 93 | + * @param integer $server |
|
| 94 | + * @param OutputInterface $output |
|
| 95 | + */ |
|
| 92 | 96 | public function update($server, $output) { |
| 93 | 97 | $output->writeln("Executing update for server: {$server}"); |
| 94 | 98 | |
@@ -3,7 +3,6 @@ |
||
| 3 | 3 | namespace Ps2alerts\Api\Command; |
| 4 | 4 | |
| 5 | 5 | use Ps2alerts\Api\Command\BaseCommand; |
| 6 | -use Symfony\Component\Console\Input\InputArgument; |
|
| 7 | 6 | use Symfony\Component\Console\Input\InputInterface; |
| 8 | 7 | use Symfony\Component\Console\Output\OutputInterface; |
| 9 | 8 | |
@@ -34,13 +34,13 @@ discard block |
||
| 34 | 34 | $servers = $this->config['servers']; |
| 35 | 35 | $servers[] = 0; |
| 36 | 36 | |
| 37 | - foreach($servers as $server) { |
|
| 37 | + foreach ($servers as $server) { |
|
| 38 | 38 | $output->writeln("Checking Server {$server}"); |
| 39 | 39 | |
| 40 | 40 | $key = "ps2alerts:api:leaderboards:status:{$server}"; |
| 41 | 41 | $resultKey = "ps2alerts:api:leaderboards:lastResult:{$server}"; |
| 42 | 42 | |
| 43 | - if (! $this->redis->exists($key)) { |
|
| 43 | + if (!$this->redis->exists($key)) { |
|
| 44 | 44 | $output->writeln("Key doesn't exist for server {$server}! Forcing!"); |
| 45 | 45 | $this->update($server, $output); |
| 46 | 46 | continue; |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | $row = $statement->fetch(\PDO::FETCH_OBJ); |
| 70 | 70 | $force = false; |
| 71 | 71 | |
| 72 | - if (! $this->redis->exists($resultKey)) { |
|
| 72 | + if (!$this->redis->exists($resultKey)) { |
|
| 73 | 73 | $force = true; |
| 74 | 74 | } else { |
| 75 | 75 | $lastResult = $this->redis->get($resultKey); |
@@ -49,7 +49,7 @@ |
||
| 49 | 49 | $data = json_decode($this->redis->get($key), true); |
| 50 | 50 | |
| 51 | 51 | if ($data['beingUpdated'] == 1) { |
| 52 | - $output->writeln("Server {$server} is currently being updated. Deferring."); |
|
| 52 | + $output->writeln("server {$server} is currently being updated. Deferring."); |
|
| 53 | 53 | continue; |
| 54 | 54 | } |
| 55 | 55 | |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | { |
| 14 | 14 | parent::configure(); // See BaseCommand.php |
| 15 | 15 | $this->setName('Leaderboards:Check') |
| 16 | - ->setDescription('Checks all leaderboards for updates'); |
|
| 16 | + ->setDescription('Checks all leaderboards for updates'); |
|
| 17 | 17 | |
| 18 | 18 | $this->redis = $this->container->get('redis'); |
| 19 | 19 | $this->config = $this->container->get('config'); |
@@ -120,6 +120,10 @@ discard block |
||
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | + /** |
|
| 124 | + * @param string $metric |
|
| 125 | + * @param integer $server |
|
| 126 | + */ |
|
| 123 | 127 | public function markAsBeingUpdated($metric, $server) |
| 124 | 128 | { |
| 125 | 129 | $key = "ps2alerts:api:leaderboards:status:{$metric}:{$server}"; |
@@ -139,6 +143,10 @@ discard block |
||
| 139 | 143 | $this->redis->set($key, json_encode($data)); |
| 140 | 144 | } |
| 141 | 145 | |
| 146 | + /** |
|
| 147 | + * @param string $metric |
|
| 148 | + * @param integer $server |
|
| 149 | + */ |
|
| 142 | 150 | public function markAsComplete($metric, $server) |
| 143 | 151 | { |
| 144 | 152 | $key = "ps2alerts:api:leaderboards:status:{$metric}:{$server}"; |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | $this->playerLeaderboards($output); |
| 28 | 28 | |
| 29 | 29 | $end = microtime(true); |
| 30 | - $output->writeln("Processing took " . gmdate("H:i:s", ($end - $start))); |
|
| 30 | + $output->writeln("Processing took ".gmdate("H:i:s", ($end - $start))); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | public function playerLeaderboards(OutputInterface $output) |
@@ -39,16 +39,16 @@ discard block |
||
| 39 | 39 | 'playerSuicides', |
| 40 | 40 | 'headshots' |
| 41 | 41 | ]; |
| 42 | - $servers = [0,1,10,13,17,25,1000,2000]; |
|
| 42 | + $servers = [0, 1, 10, 13, 17, 25, 1000, 2000]; |
|
| 43 | 43 | |
| 44 | - foreach($servers as $server) { |
|
| 45 | - foreach($metrics as $metric) { |
|
| 44 | + foreach ($servers as $server) { |
|
| 45 | + foreach ($metrics as $metric) { |
|
| 46 | 46 | $this->markAsBeingUpdated($metric, $server); |
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - foreach($servers as $server) { |
|
| 51 | - foreach($metrics as $metric) { |
|
| 50 | + foreach ($servers as $server) { |
|
| 51 | + foreach ($metrics as $metric) { |
|
| 52 | 52 | $count = 0; |
| 53 | 53 | $limit = 10000; |
| 54 | 54 | $ladderLimit = 10000; |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | if ($server !== 0) { |
| 75 | 75 | $query->where('playerServer', $server); |
| 76 | 76 | } |
| 77 | - $query->orderBy([$metric . ' DESC']); |
|
| 77 | + $query->orderBy([$metric.' DESC']); |
|
| 78 | 78 | $query->limit($limit); |
| 79 | 79 | $query->offset($count); |
| 80 | 80 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | $playerPosKey = "ps2alerts:api:leaderboards:players:pos:{$player->playerID}"; |
| 90 | 90 | |
| 91 | 91 | // If player record doesn't exist |
| 92 | - if (! $this->redis->exists($playerPosKey)) { |
|
| 92 | + if (!$this->redis->exists($playerPosKey)) { |
|
| 93 | 93 | $data = [ |
| 94 | 94 | 'id' => $player->playerID, |
| 95 | 95 | 'updated' => date('U', strtotime('now')) |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // For first time running |
| 102 | - if (! empty($data[$server][$metric])) { |
|
| 102 | + if (!empty($data[$server][$metric])) { |
|
| 103 | 103 | $data[$server][$metric]['old'] = $data[$server][$metric]['new']; |
| 104 | 104 | } else { |
| 105 | 105 | $data[$server][$metric]['old'] = 0; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | $key = "ps2alerts:api:leaderboards:status:{$metric}:{$server}"; |
| 126 | 126 | |
| 127 | 127 | // Create the key if it doesn't exist for some reason (1st runs) |
| 128 | - if (! $this->redis->exists($key)) { |
|
| 128 | + if (!$this->redis->exists($key)) { |
|
| 129 | 129 | $data = [ |
| 130 | 130 | 'beingUpdated' => 1, |
| 131 | 131 | 'lastUpdated' => 'never' |
@@ -3,7 +3,6 @@ |
||
| 3 | 3 | namespace Ps2alerts\Api\Command; |
| 4 | 4 | |
| 5 | 5 | use Ps2alerts\Api\Command\BaseCommand; |
| 6 | -use Symfony\Component\Console\Input\InputArgument; |
|
| 7 | 6 | use Symfony\Component\Console\Input\InputInterface; |
| 8 | 7 | use Symfony\Component\Console\Output\OutputInterface; |
| 9 | 8 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | { |
| 14 | 14 | parent::configure(); // See BaseCommand.php |
| 15 | 15 | $this->setName('Leaderboards:Outfits') |
| 16 | - ->setDescription('Processes all outfit leaderboards'); |
|
| 16 | + ->setDescription('Processes all outfit leaderboards'); |
|
| 17 | 17 | |
| 18 | 18 | $this->redis = $this->container->get('redis'); |
| 19 | 19 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | $query->cols(['*']); |
| 72 | 72 | $query->from('ws_players_total'); |
| 73 | 73 | if ($server !== 0) { |
| 74 | - $query->where('playerServer', $server); |
|
| 74 | + $query->where('playerServer', $server); |
|
| 75 | 75 | } |
| 76 | 76 | $query->orderBy([$metric . ' DESC']); |
| 77 | 77 | $query->limit($limit); |
@@ -184,6 +184,9 @@ discard block |
||
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | + /** |
|
| 188 | + * @param string $metric |
|
| 189 | + */ |
|
| 187 | 190 | public function markAsBeingUpdated($metric, $server) |
| 188 | 191 | { |
| 189 | 192 | $key = "ps2alerts:api:leaderboards:status:{$server}"; |
@@ -205,6 +208,9 @@ discard block |
||
| 205 | 208 | $this->redis->set($key, json_encode($data)); |
| 206 | 209 | } |
| 207 | 210 | |
| 211 | + /** |
|
| 212 | + * @param string $metric |
|
| 213 | + */ |
|
| 208 | 214 | public function markMetricAsComplete($metric, $server) |
| 209 | 215 | { |
| 210 | 216 | $key = "ps2alerts:api:leaderboards:status:{$server}"; |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | $this->playerLeaderboards($input, $output); |
| 32 | 32 | |
| 33 | 33 | $end = microtime(true); |
| 34 | - $output->writeln("Processing took " . gmdate("H:i:s", ($end - $start))); |
|
| 34 | + $output->writeln("Processing took ".gmdate("H:i:s", ($end - $start))); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | public function playerLeaderboards(InputInterface $input, OutputInterface $output) |
@@ -47,19 +47,19 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | // Allows server 0, meaning all servers but not to process every server |
| 49 | 49 | if ($serverArg === 'all') { |
| 50 | - $servers = [0,1,10,13,17,25,1000,2000]; |
|
| 50 | + $servers = [0, 1, 10, 13, 17, 25, 1000, 2000]; |
|
| 51 | 51 | } else { |
| 52 | 52 | $servers = [$serverArg]; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - foreach($servers as $server) { |
|
| 56 | - foreach($metrics as $metric) { |
|
| 55 | + foreach ($servers as $server) { |
|
| 56 | + foreach ($metrics as $metric) { |
|
| 57 | 57 | $this->markAsBeingUpdated($metric, $server); |
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - foreach($servers as $server) { |
|
| 62 | - foreach($metrics as $metric) { |
|
| 61 | + foreach ($servers as $server) { |
|
| 62 | + foreach ($metrics as $metric) { |
|
| 63 | 63 | $count = 0; |
| 64 | 64 | $limit = 10000; |
| 65 | 65 | $ladderLimit = 10000; |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | if ($server != 0) { |
| 90 | 90 | $query->where("playerServer = ?", $server); |
| 91 | 91 | } |
| 92 | - $query->orderBy([$metric . ' DESC']); |
|
| 92 | + $query->orderBy([$metric.' DESC']); |
|
| 93 | 93 | $query->limit($limit); |
| 94 | 94 | $query->offset($count); |
| 95 | 95 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | $playerPosKey = "ps2alerts:api:leaderboards:players:pos:{$player->playerID}"; |
| 105 | 105 | |
| 106 | 106 | // If player record doesn't exist |
| 107 | - if (! $this->redis->exists($playerPosKey)) { |
|
| 107 | + if (!$this->redis->exists($playerPosKey)) { |
|
| 108 | 108 | $data = [ |
| 109 | 109 | 'updated' => [ |
| 110 | 110 | 'daily' => date('U'), |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | 'monthly' |
| 123 | 123 | ]; |
| 124 | 124 | |
| 125 | - foreach($deadlines as $deadline) { |
|
| 125 | + foreach ($deadlines as $deadline) { |
|
| 126 | 126 | // Create the array if empty |
| 127 | 127 | if (empty($data[$server][$metric][$deadline])) { |
| 128 | 128 | $data[$server][$metric][$deadline] = []; |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | // Flip new to old |
| 141 | - if (! empty($row)) { |
|
| 141 | + if (!empty($row)) { |
|
| 142 | 142 | $row['old']['pos'] = $row['new']['pos']; |
| 143 | 143 | $row['old']['val'] = $row['new']['val']; |
| 144 | 144 | } |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | $key = "ps2alerts:api:leaderboards:status:{$server}"; |
| 190 | 190 | |
| 191 | 191 | // Create the key if it doesn't exist for some reason (1st runs) |
| 192 | - if (! $this->redis->exists($key)) { |
|
| 192 | + if (!$this->redis->exists($key)) { |
|
| 193 | 193 | $data = [ |
| 194 | 194 | 'beingUpdated' => 1, |
| 195 | 195 | 'lastUpdated' => date('U'), |
@@ -13,11 +13,11 @@ discard block |
||
| 13 | 13 | { |
| 14 | 14 | parent::configure(); // See BaseCommand.php |
| 15 | 15 | $this->setName('Leaderboards:Players') |
| 16 | - ->setDescription('Processes player leaderboards') |
|
| 17 | - ->addArgument( |
|
| 16 | + ->setDescription('Processes player leaderboards') |
|
| 17 | + ->addArgument( |
|
| 18 | 18 | 'server', |
| 19 | 19 | InputArgument::REQUIRED |
| 20 | - ); |
|
| 20 | + ); |
|
| 21 | 21 | |
| 22 | 22 | $this->redis = $this->container->get('redis'); |
| 23 | 23 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | $query->cols(['*']); |
| 87 | 87 | $query->from('ws_players_total'); |
| 88 | 88 | if ($server != 0) { |
| 89 | - $query->where("playerServer = ?", $server); |
|
| 89 | + $query->where("playerServer = ?", $server); |
|
| 90 | 90 | } |
| 91 | 91 | $query->orderBy([$metric . ' DESC']); |
| 92 | 92 | $query->limit($limit); |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | /** |
| 21 | 21 | * Set the http message request |
| 22 | 22 | * |
| 23 | - * @param \Zend\Diactoros\ServerRequestFactory $obj |
|
| 23 | + * @param ServerRequest $obj |
|
| 24 | 24 | */ |
| 25 | 25 | public function setRequest(ServerRequest $obj) |
| 26 | 26 | { |
@@ -30,7 +30,6 @@ discard block |
||
| 30 | 30 | /** |
| 31 | 31 | * Getthe http message request |
| 32 | 32 | * |
| 33 | - * @param \Zend\Diactoros\ServerRequestFactory $obj |
|
| 34 | 33 | */ |
| 35 | 34 | public function getRequest() |
| 36 | 35 | { |