Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Database upgrade with new tables created on core update

givanza62a4846a81b
diff --git a/admin/controller/tools/update.php b/admin/controller/tools/update.php
index 27f7f51..899fd4a 100755
--- a/admin/controller/tools/update.php
+++ b/admin/controller/tools/update.php
@@ -31,7 +31,7 @@ use Vvveb\System\User\Admin;
use function Vvveb\url;
class Update extends Base {
- private $steps = ['checkPermissions', 'download', 'unzip', /*'backup',*/ 'copySystem', /* 'copyAdmin',*/ 'copyApp', 'copyInstall', 'copyCore', 'copyConfig', 'copyPublic', 'copyPublicAdmin', 'copyPublicMedia', 'setPermissions', 'cleanUp', 'clearCache', 'complete'];
+ private $steps = ['checkPermissions', 'download', 'unzip', 'copyInstall', /*'backup',*/ 'copySystem', /* 'copyAdmin',*/ , 'createNewTables', 'copyApp', 'copyCore', 'copyConfig', 'copyPublic', 'copyPublicAdmin', 'copyPublicMedia', 'setFilePermissions', 'cleanUp', 'clearCache', 'complete'];
function __construct() {
$this->update = new UpdateSys();
@@ -187,6 +187,22 @@ class Update extends Base {
return $result;
}
+ function createNewTables() {
+ $result = false;
+
+ try {
+ $result = $this->update->createNewTables();
+ } catch (\Exception $e) {
+ $this->view->errors[] = $e->getMessage();
+ }
+
+ if ($result) {
+ $this->view->info[] = __('Create new tables successful!');
+ }
+
+ return $result;
+ }
+
function unzip() {
$errorInstallMsg = __('Error unzipping update!');
$result = true;
@@ -273,7 +289,7 @@ class Update extends Base {
return $this->copy('PublicMedia');
}
- function setPermissions() {
+ function setFilePermissions() {
$errorInstallMsg = __('Error setting permissions');
$result = false;
diff --git a/system/import/sql.php b/system/import/sql.php
index 2e9ec31..61348c7 100755
--- a/system/import/sql.php
+++ b/system/import/sql.php
@@ -149,14 +149,20 @@ class Sql {
}
}
- return $result;
+ $return = $this->db->insert_id ?: $this->db->affected_rows ?: $result;
+
+ if (! $return && ! $this->db->errorCode()) {
+ $return = true;
+ }
+
+ return $return;
}
}
return true;
}
- function createTables() {
+ function createTables($files = []) {
if (DB_ENGINE == 'sqlite') {
//try to speed up install
$query = 'pragma journal_mode = WAL;pragma synchronous = normal;pragma temp_store = memory;pragma mmap_size = 30000000000;PRAGMA writable_schema = 1;';
@@ -185,7 +191,9 @@ class Sql {
$glob = ['', '*/*/', '*/'];
//$files = glob($name, GLOB_BRACE);
- $files = globBrace($this->sqlPath, ['', '**/'], '*.sql');
+ if (!$files) {
+ $files = globBrace($this->sqlPath, ['', '**/', '*/*/'], '*.sql');
+ }
foreach ($files as $filename) {
$sql = file_get_contents($filename);
@@ -246,7 +254,7 @@ class Sql {
$glob = ['', '*/*/', '*/'];
//$files = glob($name, GLOB_BRACE);
- $files = globBrace($this->sqlPath, ['', '**/'], '*.sql');
+ $files = globBrace($this->sqlPath, ['', '**/', '*/*/'], '*.sql');
foreach ($files as $filename) {
$name = basename($filename);
diff --git a/system/update.php b/system/update.php
index 15b0ae4..6e23744 100755
--- a/system/update.php
+++ b/system/update.php
@@ -184,13 +184,13 @@ class Update {
}
function copyCore() {
- $skipFolders = ['plugins', 'public', 'storage', 'system', 'app', 'admin', 'install', 'config', 'env.php'];
+ $skipFolders = ['plugins', 'public', 'storage', 'system', 'app', 'admin', 'install', 'config', 'vendor', 'env.php'];
return $this->copyFolder($this->workDir, DIR_ROOT, $skipFolders);
}
function copyConfig() {
- $skip = ['plugins.php', 'mail.php', 'sites.php', 'app.php', 'admin.php', 'routes.php', 'env.php'];
+ $skip = ['plugins.php', 'mail.php', 'sites.php', 'app.php', 'admin.php', 'app-routes.php'];
return $this->copyFolder($this->workDir . DS . 'config', DIR_ROOT . DS . 'config', $skip);
}
@@ -214,6 +214,41 @@ class Update {
return $this->copyFolder($this->workDir . DS . 'public' . DS . 'media', DIR_PUBLIC . DS . 'media', $skipFolders);
}
+ function createNewTables() {
+ $db = \Vvveb\System\Db::getInstance();
+ $tableNames = $db->getTableNames();
+
+ $driver = DB_ENGINE;
+ $sqlPath = DIR_ROOT . "install/sql/$driver/";
+ $files = \Vvveb\globBrace($sqlPath, ['', '*/*/'], '*.sql');
+
+ $diff = [];
+ //if the number of tables is less than in the install dir
+ if (count($tableNames) < count($files)) {
+ $tableSql = [];
+ //get table names from sql files
+ foreach ($files as $filename) {
+ $tableSql[] = basename($filename, '.sql');
+ }
+ //get the names of missing tables
+ $diff = array_diff($tableSql, $tableNames);
+ }
+
+ $sqlFiles = [];
+ //get files for missing tables
+ foreach ($diff as $key => $tableName) {
+ $sqlFiles[] = $files[$key];
+ }
+
+ //create missing tables
+ if ($sqlFiles) {
+ $sqlImport = new \Vvveb\System\Import\Sql();
+ $sqlImport->createTables($sqlFiles);
+ }
+
+ return true;
+ }
+
function clearCache() {
return CacheManager::delete();
}
@@ -235,7 +270,7 @@ class Update {
//$dest = substr(DIR_ROOT,0, -1); //remove trailing slash
rrmdir($this->workDir);
//plugins and themes are updated individually
- $skipFolders = ['plugins', 'public' . DS . 'themes', 'storage'];
+ $skipFolders = ['plugins', 'public' . DS . 'themes', 'storage', 'vendor'];
rcopy($this->workDir, DIR_ROOT, $skipFolders);
rrmdir($this->workDir);