Пример #1
0
 public function __construct()
 {
     if (!self::$db) {
         self::$db = SafeMySQL::getInstance();
     }
     parent::__construct();
 }
Пример #2
0
<?php

include_once '../settings/autoload.php';
$msql = SafeMySQL::getInstance();
$ce = new CatchErrors();
// Check double success attempts
$sql = "SELECT order_id\n        FROM `attempts`\n        WHERE `status`='success'\n        GROUP BY attempt_type, order_id\n        HAVING COUNT(*)>1";
$ce->checkSQL($sql, 'Double success attempts');
// Check attempts with new status
$sql = "SELECT order_id\n        FROM `attempts`\n        WHERE `status`='new'\n        AND `updated` < DATE_SUB(NOW(), INTERVAL 10 MINUTE)";
$ce->checkSQL($sql, 'Attempts with new status more than 10 minutes');
// Check attempts with inprogress status
$sql = "SELECT order_id\n        FROM `attempts`\n        WHERE `status`='inprogress'\n        AND `updated` < DATE_SUB(NOW(), INTERVAL 20 MINUTE)";
$ce->checkSQL($sql, 'Attempts with inprogress status more than 10 minutes');
// Check attempts with submitted status
$sql = "SELECT order_id\n        FROM `attempts`\n        WHERE `status`='submitted'\n        AND `updated` < DATE_SUB(NOW(), INTERVAL 5 DAY)";
$ce->checkSQL($sql, 'Attempts with submitted status more than 5 days');
// Check attempts with unknown status
$sql = "SELECT order_id\n        FROM `attempts`\n        WHERE `status`='unknown'\n        AND `updated` < DATE_SUB(NOW(), INTERVAL 10 MINUTE)";
$ce->checkSQL($sql, 'Attempts with unknown status more than 10 minutes');
// Check correctness attempts.attempt_number
$sql = "SELECT order_id\n        FROM `attempts`\n        WHERE 1\n        GROUP BY order_id, attempt_number\n        HAVING COUNT(*) > 1";
$ce->checkSQL($sql, 'Incorrect attempts.`attempt_number` values');
// Check sum order attempts amount and order payment total
$sql = "SELECT t.order_id\nFROM (\nSELECT\n\to.order_id,\n\tSUM(IF(a.`attempt_type` = 'debit', a.`amount`, 0)) - SUM(IF(a.`attempt_type` = 'credit', a.`amount`, 0)) as sum,\n\to.`payment_total`\nFROM orders as o\nJOIN `attempts` as a USING(`order_id`)\nWHERE a.`status`='success'\nGROUP BY a.order_id\nHAVING sum != o.`payment_total` OR o.`payment_total` < 0\nORDER BY `sum`\n) as t";
$ce->checkSQL($sql, 'Different amounts between an attempt amount and an order total');
// Check conformity between orders flags and statuses
$sql = "SELECT order_id\nFROM orders as o\nWHERE FIND_IN_SET('test', o.`flags`)=0\nAND (\n\t( o.`status` = 'error' AND FIND_IN_SET('paid', o.`flags`)>0 )\n\tOR\n\t( o.`status` IN ('ok', 'void', 'sent', 'shipped', 'returned') AND FIND_IN_SET('paid', o.`flags`)=0 )\n\tOR\n\t( o.`status` IN ('ok', 'void', 'sent', 'shipped', 'returned') AND FIND_IN_SET('pay', o.`flags`)>0 )\n\tOR\n\t( o.`status` = 'new' AND  FIND_IN_SET('paid', o.`flags`)>0)\n\tOR\n\t( FIND_IN_SET('pay', o.`flags`)>0 AND FIND_IN_SET('paid', o.`flags`)>0 )\n)";
$ce->checkSQL($sql, 'Discrepancy between order flags and statuses');
$ce->notify();
unset($ce);