| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- trait UpgradeFunctions
- {
- public function upgradeToVersion($version = '2.1.0')
- {
- switch ($version) {
- case '2.1.0':
- $this->upgradeSettingsTabURL();
- $this->upgradeHomepageTabURL();
- case '2.1.400':
- $this->removeOldPluginDirectoriesAndFiles();
- case '2.1.525':
- $this->removeOldCustomHTML();
- default:
- $this->setAPIResponse('success', 'Ran update function for version: ' . $version, 200);
- return true;
- }
- }
-
- public function upgradeSettingsTabURL()
- {
- $response = [
- array(
- 'function' => 'query',
- 'query' => array(
- 'UPDATE tabs SET',
- ['url' => 'api/v2/page/settings'],
- 'WHERE url = ?',
- 'api/?v1/settings/page'
- )
- ),
- ];
- return $this->processQueries($response);
- }
-
- public function upgradeHomepageTabURL()
- {
- $response = [
- array(
- 'function' => 'query',
- 'query' => array(
- 'UPDATE tabs SET',
- ['url' => 'api/v2/page/homepage'],
- 'WHERE url = ?',
- 'api/?v1/homepage/page'
- )
- ),
- ];
- return $this->processQueries($response);
- }
-
- public function removeOldPluginDirectoriesAndFiles()
- {
- $folders = [
- $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'api',
- $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'config',
- $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'css',
- $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'js',
- $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'misc',
- ];
- $files = [
- $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'bookmark.php',
- $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'chat.php',
- $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'healthChecks.php',
- $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'invites.php',
- $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'php-mailer.php',
- $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'speedTest.php',
- ];
- foreach ($files as $file) {
- if (file_exists($file)) {
- @unlink($file);
- }
- }
- foreach ($folders as $folder) {
- if (file_exists($folder)) {
- @$this->rrmdir($folder);
- }
- }
- return true;
- }
-
- public function checkForConfigKeyAddToArray($keys)
- {
- $updateItems = [];
- foreach ($keys as $new => $old) {
- if (isset($this->config[$old])) {
- if ($this->config[$old] !== '') {
- $updateItemsNew = [$new => $this->config[$old]];
- $updateItems = array_merge($updateItems, $updateItemsNew);
- }
- }
- }
- return $updateItems;
- }
-
- public function removeOldCustomHTML()
- {
- $backup = $this->backupOrganizr();
- if ($backup) {
- $keys = [
- 'homepageCustomHTML01Enabled' => 'homepageCustomHTMLoneEnabled',
- 'homepageCustomHTML01Auth' => 'homepageCustomHTMLoneAuth',
- 'customHTML01' => 'customHTMLone',
- 'homepageCustomHTML02Enabled' => 'homepageCustomHTMLtwoEnabled',
- 'homepageCustomHTML02Auth' => 'homepageCustomHTMLtwoAuth',
- 'customHTML02' => 'customHTMLtwo',
- ];
- $updateItems = $this->checkForConfigKeyAddToArray($keys);
- $updateComplete = false;
- if (!empty($updateItems)) {
- $updateComplete = $this->updateConfig($updateItems);
- }
- if ($updateComplete) {
- $removeConfigItems = $this->removeConfigItem(['homepagCustomHTMLoneAuth', 'homepagCustomHTMLoneEnabled', 'homepagCustomHTMLtwoAuth', 'homepagCustomHTMLtwoEnabled', 'homepageOrdercustomhtml', 'homepageOrdercustomhtmlTwo', 'homepageCustomHTMLoneEnabled', 'homepageCustomHTMLoneAuth', 'customHTMLone', 'homepageCustomHTMLtwoEnabled', 'homepageCustomHTMLtwoAuth', 'customHTMLtwo']);
- if ($removeConfigItems) {
- return true;
- }
- }
- }
- return false;
- }
- }
|