-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #974 from M0rgan01/improve-php-script-errors
Improve php script error checking
- Loading branch information
Showing
34 changed files
with
579 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright since 2007 PrestaShop SA and Contributors | ||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0) | ||
* that is bundled with this package in the file LICENSE.md. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/AFL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://devdocs.prestashop.com/ for more information. | ||
* | ||
* @author PrestaShop SA and Contributors <contact@prestashop.com> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) | ||
*/ | ||
|
||
namespace PrestaShop\Module\AutoUpgrade; | ||
|
||
use Db; | ||
use mysqli_result; | ||
use PDOStatement; | ||
use PrestaShop\Module\AutoUpgrade\Exceptions\UpdateDatabaseException; | ||
|
||
class DbWrapper | ||
{ | ||
/** | ||
* @param array<mixed> $data | ||
* | ||
* @throws UpdateDatabaseException | ||
*/ | ||
public static function update(string $table, array $data, string $where = '', int $limit = 0, bool $null_values = false, bool $use_cache = true, bool $add_prefix = true): bool | ||
{ | ||
$result = Db::getInstance()->update($table, $data, $where, $limit, $null_values, $use_cache, $add_prefix); | ||
self::validateDBQuerySuccess(); | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @throws UpdateDatabaseException | ||
*/ | ||
public static function execute(string $sql, bool $use_cache = true): bool | ||
{ | ||
$result = Db::getInstance()->execute($sql, $use_cache); | ||
self::validateDBQuerySuccess(); | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @throws UpdateDatabaseException | ||
* | ||
* @return array<mixed>|bool|mysqli_result|PDOStatement|resource|null | ||
*/ | ||
public static function executeS(string $sql, bool $array = true, bool $use_cache = true) | ||
{ | ||
$result = Db::getInstance()->executeS($sql, $array, $use_cache); | ||
self::validateDBQuerySuccess(); | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @throws UpdateDatabaseException | ||
* | ||
* @return string|false|null Returns false if no results | ||
*/ | ||
public static function getValue(string $sql, bool $use_cache = true) | ||
{ | ||
$result = Db::getInstance()->getValue($sql, $use_cache); | ||
self::validateDBQuerySuccess(); | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @param array<mixed> $data | ||
* | ||
* @throws UpdateDatabaseException | ||
*/ | ||
public static function insert(string $table, array $data, bool $null_values = false, bool $use_cache = true, int $type = Db::INSERT, bool $add_prefix = true): bool | ||
{ | ||
$result = Db::getInstance()->insert($table, $data, $null_values, $use_cache, $type, $add_prefix); | ||
self::validateDBQuerySuccess(); | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @return int|string | ||
* | ||
* @throws UpdateDatabaseException | ||
*/ | ||
public static function Insert_ID() | ||
{ | ||
$result = Db::getInstance()->Insert_ID(); | ||
self::validateDBQuerySuccess(); | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @throws UpdateDatabaseException | ||
*/ | ||
public static function delete(string $table, string $where = '', int $limit = 0, bool $use_cache = true, bool $add_prefix = true): bool | ||
{ | ||
$result = Db::getInstance()->delete($table, $where, $limit, $use_cache, $add_prefix); | ||
self::validateDBQuerySuccess(); | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @throws UpdateDatabaseException | ||
* | ||
* @return array<mixed>|bool|object|null | ||
*/ | ||
public static function getRow(string $sql, bool $use_cache = true) | ||
{ | ||
$result = Db::getInstance()->getRow($sql, $use_cache); | ||
self::validateDBQuerySuccess(); | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @throws UpdateDatabaseException | ||
*/ | ||
public static function validateDBQuerySuccess(): void | ||
{ | ||
$previousQueryError = Db::getInstance()->getMsgError(); | ||
$previousQueryErrorCode = Db::getInstance()->getNumberError(); | ||
|
||
if (!empty($previousQueryError) || !empty($previousQueryErrorCode)) { | ||
throw new UpdateDatabaseException($previousQueryError, $previousQueryErrorCode); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright since 2007 PrestaShop SA and Contributors | ||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0) | ||
* that is bundled with this package in the file LICENSE.md. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/AFL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://devdocs.prestashop.com/ for more information. | ||
* | ||
* @author PrestaShop SA and Contributors <contact@prestashop.com> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) | ||
*/ | ||
|
||
namespace PrestaShop\Module\AutoUpgrade\Exceptions; | ||
|
||
use Exception; | ||
|
||
class UpdateDatabaseException extends Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.