diff --git a/bl-plugins/updater/languages/en.json b/bl-plugins/updater/languages/en.json new file mode 100644 index 00000000..b8347111 --- /dev/null +++ b/bl-plugins/updater/languages/en.json @@ -0,0 +1,7 @@ +{ + "plugin-data": + { + "name": "Updater", + "description": "" + } +} \ No newline at end of file diff --git a/bl-plugins/updater/metadata.json b/bl-plugins/updater/metadata.json new file mode 100644 index 00000000..13635940 --- /dev/null +++ b/bl-plugins/updater/metadata.json @@ -0,0 +1,10 @@ +{ + "author": "Bludit", + "email": "", + "website": "https://plugins.bludit.com", + "version": "2.3", + "releaseDate": "2018-01-23", + "license": "MIT", + "compatible": "2.3", + "notes": "" +} \ No newline at end of file diff --git a/bl-plugins/updater/plugin.php b/bl-plugins/updater/plugin.php new file mode 100644 index 00000000..0fa92262 --- /dev/null +++ b/bl-plugins/updater/plugin.php @@ -0,0 +1,168 @@ +formButtons = false; + + // Check for zip extension installed + $this->zip = extension_loaded('zip'); + } + + // Install the plugin and create the workspace directory + public function install($position=0) + { + parent::install($position); + $workspace = $this->workspace(); + return mkdir($workspace, 0755, true); + } + + // Uninstall the plugin and delete the workspace directory + public function uninstall() + { + parent::uninstall(); + $workspace = $this->workspace(); + return Filesystem::deleteRecursive($workspace); + } + + // Redefine workspace + public function workspace() + { + return PATH_CONTENT.'updater'.DS; + } + + // Check if the root directory is writable + private function isWritable() + { + return is_writable(PATH_ROOT); + } + + // Create a copy of all the system and compress it + // Returns the name of the backup directory + private function makeFullBackup() + { + $currentDate = Date::current(BACKUP_DATE_FORMAT); + $backupDirectory = $this->workspace().$currentDate; + + // Copy all the files to a backup directory formed by date + Filesystem::copyRecursive(PATH_CONTENT, $backupDirectory, $backupDirectory); + + // Compress the backup directory + if (Filesystem::zip($backupDirectory, $backupDirectory.'.zip')) { + Filesystem::deleteRecursive($backupDirectory); + } + + return $backupDirectory; + } + + // Download the latest version of Bludit + private function downloadLatestVersion() + { + TCP::download('https://bludit-latest.zip', $this->workspace().DS.'bludit-latest.zip'); + } + + public function post() + { + if (isset($_POST['createBackup'])) { + return $this->createBackup(); + } elseif (isset($_POST['restoreBackup'])) { + return $this->restoreBackup($_POST['restoreBackup']); + } elseif (isset($_POST['deleteBackup'])) { + return $this->deleteBackup($_POST['deleteBackup']); + } + + return false; + } + + public function form() + { + global $Language; + + $backups = Filesystem::listDirectories($this->workspace(), '*', true); + if ($this->zip) { + $backups = Filesystem::listFiles($this->workspace(), '*', 'zip', true); + } + + $html = '