| <?php |
|
|
| |
| |
| |
| |
| |
| |
|
|
| namespace Piwik\Updater\Migration\Db; |
|
|
| use Piwik\Common; |
| use Piwik\Config; |
| use Piwik\Db; |
| use Piwik\Updater\Migration\Db as DbMigration; |
|
|
| |
| |
| |
| |
| |
| |
| class Sql extends DbMigration |
| { |
| |
| |
| |
| protected $sql; |
|
|
| |
| |
| |
| private $errorCodesToIgnore; |
|
|
| |
| |
| |
| |
| |
| |
| public function __construct($sql, $errorCodesToIgnore) |
| { |
| if (!is_array($errorCodesToIgnore)) { |
| $errorCodesToIgnore = array($errorCodesToIgnore); |
| } |
|
|
| $this->sql = $sql; |
| $globalErrorCodesToIgnore = Config::getInstance()->database['ignore_error_codes'] ?? []; |
| $this->errorCodesToIgnore = array_merge($errorCodesToIgnore, (is_array($globalErrorCodesToIgnore) ? $globalErrorCodesToIgnore : [])); |
| } |
|
|
| public function shouldIgnoreError($exception) |
| { |
| if (empty($this->errorCodesToIgnore)) { |
| return false; |
| } |
|
|
| foreach ($this->errorCodesToIgnore as $code) { |
| if (Db::get()->isErrNo($exception, $code)) { |
| return true; |
| } |
| } |
|
|
| return false; |
| } |
|
|
| |
| |
| |
| |
| |
| public function addErrorCodeToIgnore($errorCode) |
| { |
| $this->errorCodesToIgnore[] = $errorCode; |
|
|
| return $this; |
| } |
|
|
| |
| |
| |
| public function getErrorCodesToIgnore() |
| { |
| return $this->errorCodesToIgnore; |
| } |
|
|
| public function __toString() |
| { |
| $sql = $this->sql; |
|
|
| if (!empty($sql) && !Common::stringEndsWith($sql, ';')) { |
| $sql .= ';'; |
| } |
|
|
| return $sql; |
| } |
|
|
| public function exec() |
| { |
| if (!empty($this->sql)) { |
| Db::exec($this->sql); |
| } |
| } |
| } |
|
|