diff --git a/objects/mysql_dal.php b/objects/mysql_dal.php index 54f284c1ed..36a73b4623 100644 --- a/objects/mysql_dal.php +++ b/objects/mysql_dal.php @@ -89,13 +89,19 @@ class sqlDAL * @return boolean true on success, false on fail */ - public static function writeSql($preparedStatement, $formats = "", $values = []) + public static function writeSql($preparedStatement, $formats = "", $values = [], $try=0) { global $global, $disableMysqlNdMethods; if (empty($preparedStatement)) { _error_log("writeSql empty(preparedStatement)"); return false; } + + /** + * + * @var array $global + * @var object $global['mysqli'] + */ // make sure it does not store autid transactions $debug = debug_backtrace(); if (empty($debug[2]['class']) || $debug[2]['class'] !== "AuditTable") { @@ -104,6 +110,7 @@ class sqlDAL try { $audit->exec(@$debug[1]['function'], @$debug[1]['class'], $preparedStatement, $formats, json_encode($values), User::getId()); } catch (Exception $exc) { + _error_log('Error in writeSql: ' . $global['mysqli']->errno . " " . $global['mysqli']->error . ' ' . $preparedStatement); log_error($exc->getTraceAsString()); } } @@ -120,12 +127,6 @@ class sqlDAL if (!_mysql_is_open()) { _mysql_connect(); } - - /** - * - * @var array $global - * @var object $global['mysqli'] - */ if (!($stmt = $global['mysqli']->prepare($preparedStatement))) { log_error("[sqlDAL::writeSql] Prepare failed: (" . $global['mysqli']->errno . ") " . $global['mysqli']->error . " preparedStatement = " . json_encode($preparedStatement) . @@ -140,7 +141,11 @@ class sqlDAL try { $stmt->execute(); } catch (Exception $exc) { - if (preg_match('/playlists_has_videos/', $preparedStatement)) { + if (empty($try) && $stmt->errno == 2006) { //MySQL server has gone away + _mysql_close(); + _mysql_connect(); + return self::writeSql($preparedStatement, $formats, $values, $try+1); + }else if (preg_match('/playlists_has_videos/', $preparedStatement)) { log_error('Error in writeSql values: ' . json_encode($values)); }else if (preg_match('/Illegal mix of collations.*and \(utf8mb4/i', $global['mysqli']->error)) { try { @@ -173,12 +178,10 @@ class sqlDAL } sqlDAL::eval_mysql_bind($stmt, $formats, $values); try { - log_error('try again 2'); $stmt->execute(); log_error('try again 2 SUCCESS'); } catch (Exception $exc) { - log_error($exc->getTraceAsString()); log_error('Error in writeSql stmt->execute: ' . $global['mysqli']->errno . " " . $global['mysqli']->error . ' ' . $preparedStatement); } @@ -218,14 +221,31 @@ class sqlDAL public static function writeSqlTry($preparedStatement, $formats = "", $values = []) { + global $global; + + /** + * @var array $global + * @var object $global['mysqli'] + */ try { - return self::writeSql($preparedStatement, $formats, $values); + $return = self::writeSql($preparedStatement, $formats, $values); + if(!$return){ + _error_log('Error in writeSqlTry return: ' . $global['mysqli']->errno . " " . $global['mysqli']->error . ' ' . $preparedStatement); + } + return $return; } catch (\Throwable $th) { - _error_log($th->getMessage(), AVideoLog::$ERROR); + _error_log('Error in writeSqlTry: ' . $global['mysqli']->errno . " " . $global['mysqli']->error . ' ' . $preparedStatement); + _error_log('writeSqlTry: '.$th->getMessage(), AVideoLog::$ERROR); $search = array('COLUMN IF NOT EXISTS', 'IF NOT EXISTS'); $replace = array('COLUMN', 'COLUMN'); $preparedStatement = str_ireplace($search, $replace, $preparedStatement); - return self::writeSql($preparedStatement, $formats, $values); + try { + return self::writeSql($preparedStatement, $formats, $values); + } catch (\Throwable $th) { + _error_log('Error in writeSqlTry retry: ' . $global['mysqli']->errno . " " . $global['mysqli']->error . ' ' . $preparedStatement); + _error_log('writeSqlTry retry: '.$th->getMessage(), AVideoLog::$ERROR); + return false; + } } } diff --git a/objects/plugin.php b/objects/plugin.php index 57689326bc..5c8c5e9a19 100644 --- a/objects/plugin.php +++ b/objects/plugin.php @@ -14,7 +14,7 @@ class Plugin extends ObjectYPT protected $name; protected $uuid; protected $dirName; - protected $pluginVersion; + protected $pluginversion; public static function getSearchFieldsNames() { @@ -43,7 +43,7 @@ class Plugin extends ObjectYPT public function getPluginVersion() { - return $this->pluginVersion; + return $this->pluginversion; } public function getName() @@ -96,7 +96,7 @@ class Plugin extends ObjectYPT public function setPluginversion($pluginVersion) { - $this->pluginVersion = $pluginVersion; + $this->pluginversion = $pluginVersion; } public static function setCurrentVersionByUuid($uuid, $currentVersion) diff --git a/objects/pluginRunUpdateScript.json.php b/objects/pluginRunUpdateScript.json.php index cb32dc47d9..9126f79973 100644 --- a/objects/pluginRunUpdateScript.json.php +++ b/objects/pluginRunUpdateScript.json.php @@ -7,14 +7,15 @@ if (!isset($global['systemRootPath'])) { require_once $global['systemRootPath'] . 'objects/user.php'; require_once $global['systemRootPath'] . 'objects/plugin.php'; if (!User::isAdmin()) { - die('{"error":"' . __("Permission denied") . '"}'); + forbiddenPage('Permission denied'); } if (empty($_POST['name'])) { - die('{"error":"' . __("Name can't be blank") . '"}'); + forbiddenPage('Name can\'t be blank'); } ini_set('max_execution_time', 300); require_once $global['systemRootPath'] . 'plugin/AVideoPlugin.php'; -$res = AVideoPlugin::updatePlugin($_POST['name']); - -die(json_encode($res)); +$obj = new stdClass(); +$obj->error = !AVideoPlugin::updatePlugin($_POST['name']); +$obj->msg = ''; +die(json_encode($obj)); diff --git a/objects/pluginSwitch.json.php b/objects/pluginSwitch.json.php index 4cba6f5285..8115acfe95 100644 --- a/objects/pluginSwitch.json.php +++ b/objects/pluginSwitch.json.php @@ -7,13 +7,14 @@ if (!isset($global['systemRootPath'])) { require_once $global['systemRootPath'] . 'objects/user.php'; require_once $global['systemRootPath'] . 'objects/plugin.php'; if (!User::isAdmin()) { - die('{"error":"'.__("Permission denied").'"}'); + forbiddenPage('Permission denied'); } if (empty($_POST['name'])) { + forbiddenPage('Name can\'t be blank'); die('{"error":"'.__("Name can't be blank").'"}'); } if (empty($_POST['uuid'])) { - die('{"error":"'.__("UUID can't be blank").'"}'); + forbiddenPage('UUID can\'t be blank'); } $obj = new Plugin(0); $obj->loadFromUUID($_POST['uuid']); diff --git a/plugin/AVideoPlugin.php b/plugin/AVideoPlugin.php index d810c8e3f8..c2e9ea2c32 100644 --- a/plugin/AVideoPlugin.php +++ b/plugin/AVideoPlugin.php @@ -1334,6 +1334,7 @@ class AVideoPlugin $currentVersion = $p->getPluginVersion(); $uuid = $p->getUUID(); _error_log("AVideoPlugin::updatePlugin name=($name) uuid=($uuid) "); + //var_dump($name, method_exists($p, 'updateScript'));exit; if (method_exists($p, 'updateScript')) { _error_log("AVideoPlugin::updatePlugin method_exists ", AVideoLog::$WARNING); if ($p->updateScript()) { diff --git a/plugin/Plugin.abstract.php b/plugin/Plugin.abstract.php index d0ab45527a..d56dd39f26 100644 --- a/plugin/Plugin.abstract.php +++ b/plugin/Plugin.abstract.php @@ -43,6 +43,7 @@ abstract class PluginAbstract { $pattern = '/updateV([\d\.]+)\.sql$/'; // This pattern will match files like "updateV2.0.sql" and capture the version "2.0" $dir = $global['systemRootPath'] . "plugin/{$pluginName}/install/"; + //var_dump($dir);exit; if(is_dir($dir)){ $files = scandir($dir); @@ -64,16 +65,27 @@ abstract class PluginAbstract { // Iterate through sorted files foreach ($versions as $entry) { + //var_dump($pluginName, $entry['version'], AVideoPlugin::compareVersion($pluginName, $entry['version']) < 0); if (AVideoPlugin::compareVersion($pluginName, $entry['version']) < 0) { _error_log("Update plugin {$pluginName} to version {$entry['version']}"); $filename = $dir . '/' . $entry['filename']; $sqls = file_get_contents($filename); $sqlParts = explode(";", $sqls); + //var_dump($sqlParts); foreach ($sqlParts as $value) { - sqlDal::writeSqlTry(trim($value)); + $sql = trim($value); + if(empty($sql)){ + continue; + } + if(sqlDal::writeSqlTry($sql)){ + _error_log("Update plugin {$pluginName} to version {$entry['version']} SQL success"); + }else{ + _error_log("Update plugin {$pluginName} to version {$entry['version']} SQL error: {$value}"); + } } } - }$files = scandir($dir); + } + $files = scandir($dir); $versions = []; diff --git a/view/managerPlugins_body.php b/view/managerPlugins_body.php index 7256eb1ab2..d1b0816462 100644 --- a/view/managerPlugins_body.php +++ b/view/managerPlugins_body.php @@ -659,6 +659,7 @@ $wwbnIndexPlugin = AVideoPlugin::isEnabledByName('WWBNIndex'); success: function(response) { modal.hidePleaseWait(); $("#grid").bootgrid('reload'); + avideoResponse(response); } }); });