upgrade-functions.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <?php
  2. trait UpgradeFunctions
  3. {
  4. public function upgradeCheck()
  5. {
  6. if ($this->hasDB()) {
  7. $tempLock = $this->config['dbLocation'] . 'DBLOCK.txt';
  8. $updateComplete = $this->config['dbLocation'] . 'completed.txt';
  9. $cleanup = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'upgrade' . DIRECTORY_SEPARATOR;
  10. if (file_exists($updateComplete)) {
  11. @unlink($updateComplete);
  12. @$this->rrmdir($cleanup);
  13. }
  14. if (file_exists($tempLock)) {
  15. die($this->showHTML('Upgrading', 'Please wait...'));
  16. }
  17. $updateDB = false;
  18. $updateSuccess = true;
  19. $compare = new Composer\Semver\Comparator;
  20. $oldVer = $this->config['configVersion'];
  21. // Upgrade check start for version below
  22. $versionCheck = '2.0.0-beta-200';
  23. if ($compare->lessThan($oldVer, $versionCheck)) {
  24. $updateDB = true;
  25. $oldVer = $versionCheck;
  26. }
  27. // End Upgrade check start for version above
  28. // Upgrade check start for version below
  29. $versionCheck = '2.0.0-beta-500';
  30. if ($compare->lessThan($oldVer, $versionCheck)) {
  31. $updateDB = true;
  32. $oldVer = $versionCheck;
  33. }
  34. // End Upgrade check start for version above
  35. // Upgrade check start for version below
  36. $versionCheck = '2.0.0-beta-800';
  37. if ($compare->lessThan($oldVer, $versionCheck)) {
  38. $updateDB = true;
  39. $oldVer = $versionCheck;
  40. }
  41. // End Upgrade check start for version above
  42. // Upgrade check start for version below
  43. $versionCheck = '2.1.0';
  44. if ($compare->lessThan($oldVer, $versionCheck)) {
  45. $updateDB = false;
  46. $oldVer = $versionCheck;
  47. $this->upgradeToVersion($versionCheck);
  48. }
  49. // End Upgrade check start for version above
  50. // Upgrade check start for version below
  51. $versionCheck = '2.1.400';
  52. if ($compare->lessThan($oldVer, $versionCheck)) {
  53. $updateDB = false;
  54. $oldVer = $versionCheck;
  55. $this->upgradeToVersion($versionCheck);
  56. }
  57. // End Upgrade check start for version above
  58. // Upgrade check start for version below
  59. $versionCheck = '2.1.525';
  60. if ($compare->lessThan($oldVer, $versionCheck)) {
  61. $updateDB = false;
  62. $oldVer = $versionCheck;
  63. $this->upgradeToVersion($versionCheck);
  64. }
  65. // End Upgrade check start for version above
  66. // Upgrade check start for version below
  67. $versionCheck = '2.1.860';
  68. if ($compare->lessThan($oldVer, $versionCheck)) {
  69. $updateDB = false;
  70. $oldVer = $versionCheck;
  71. $this->upgradeToVersion($versionCheck);
  72. }
  73. // End Upgrade check start for version above
  74. // Upgrade check start for version below
  75. $versionCheck = '2.1.1500';
  76. if ($compare->lessThan($oldVer, $versionCheck)) {
  77. $updateDB = false;
  78. $oldVer = $versionCheck;
  79. $this->upgradeToVersion($versionCheck);
  80. }
  81. // End Upgrade check start for version above
  82. if ($updateDB == true) {
  83. //return 'Upgraded Needed - Current Version '.$oldVer.' - New Version: '.$versionCheck;
  84. // Upgrade database to latest version
  85. $updateSuccess = $this->updateDB($oldVer);
  86. }
  87. // Update config.php version if different to the installed version
  88. if ($updateSuccess && $this->version !== $this->config['configVersion']) {
  89. $this->updateConfig(array('apply_CONFIG_VERSION' => $this->version));
  90. $this->setLoggerChannel('Update');
  91. $this->logger->debug('Updated config version to ' . $this->version);
  92. }
  93. if ($updateSuccess == false) {
  94. die($this->showHTML('Database update failed', 'Please manually check logs and fix - Then reload this page'));
  95. }
  96. return true;
  97. }
  98. }
  99. public function addColumnToDatabase($table = '', $columnName = '', $definition = 'TEXT')
  100. {
  101. if ($table == '' || $columnName == '' || $definition == '') {
  102. return false;
  103. }
  104. if ($this->hasDB()) {
  105. if ($this->config['driver'] === 'sqlite3') {
  106. $term = 'SELECT COUNT(*) AS has_column FROM pragma_table_info(?) WHERE name=?';
  107. } else {
  108. $term = 'SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = "' . $this->config['dbName'] . '" AND TABLE_NAME=? AND COLUMN_NAME=?';
  109. }
  110. $tableInfo = [
  111. array(
  112. 'function' => 'fetchSingle',
  113. 'query' => array(
  114. $term,
  115. (string)$table,
  116. (string)$columnName
  117. )
  118. )
  119. ];
  120. $query = $this->processQueries($tableInfo);
  121. if (!$query) {
  122. $columnAlter = [
  123. array(
  124. 'function' => 'query',
  125. 'query' => ['ALTER TABLE %n ADD %n ' . (string)$definition,
  126. (string)$table,
  127. (string)$columnName,
  128. ]
  129. )
  130. ];
  131. $AlterQuery = $this->processQueries($columnAlter);
  132. if ($AlterQuery) {
  133. $query = $this->processQueries($tableInfo);
  134. if ($query) {
  135. return true;
  136. }
  137. }
  138. } else {
  139. return true;
  140. }
  141. }
  142. return false;
  143. }
  144. public function createMysqliDatabase($database, $migration = false)
  145. {
  146. $query = [
  147. array(
  148. 'function' => 'fetchAll',
  149. 'query' => array(
  150. 'DROP DATABASE IF EXISTS tempMigration'
  151. )
  152. ),
  153. array(
  154. 'function' => 'fetchAll',
  155. 'query' => array(
  156. 'CREATE DATABASE IF NOT EXISTS %n',
  157. $database
  158. )
  159. ),
  160. ];
  161. //$query = ['CREATE DB %n', $database];
  162. return $this->processQueries($query, $migration);
  163. }
  164. public function updateDB($oldVerNum = false)
  165. {
  166. $tempLock = $this->config['dbLocation'] . 'DBLOCK.txt';
  167. if (!file_exists($tempLock)) {
  168. touch($tempLock);
  169. $migrationDB = 'tempMigration.db';
  170. $pathDigest = pathinfo($this->config['dbLocation'] . $this->config['dbName']);
  171. // Delete old backup sqlite db if exists
  172. if (file_exists($this->config['dbLocation'] . $migrationDB)) {
  173. unlink($this->config['dbLocation'] . $migrationDB);
  174. }
  175. // Create Temp DB First
  176. $this->createNewDB('tempMigration', true);
  177. $this->connectOtherDB();
  178. if ($this->config['driver'] == 'sqlite3') {
  179. // Backup sqlite database
  180. $backupDB = $pathDigest['dirname'] . '/' . $pathDigest['filename'] . '[' . date('Y-m-d_H-i-s') . ']' . ($oldVerNum ? '[' . $oldVerNum . ']' : '') . '.bak.db';
  181. copy($this->config['dbLocation'] . $this->config['dbName'], $backupDB);
  182. }
  183. $success = $this->createDB($this->config['dbLocation'], true);
  184. if ($success) {
  185. switch ($this->config['driver']) {
  186. case 'sqlite3':
  187. $query = 'SELECT name FROM sqlite_master WHERE type="table"';
  188. break;
  189. case 'mysqli':
  190. $query = 'SELECT Table_name as name from information_schema.tables where table_schema = "tempMigration"';
  191. break;
  192. }
  193. $response = [
  194. array(
  195. 'function' => 'fetchAll',
  196. 'query' => array(
  197. $query
  198. )
  199. ),
  200. ];
  201. $tables = $this->processQueries($response);
  202. $defaultTables = $this->getDefaultTablesFormatted();
  203. foreach ($tables as $table) {
  204. if (in_array($table['name'], $defaultTables)) {
  205. $response = [
  206. array(
  207. 'function' => 'fetchAll',
  208. 'query' => array(
  209. 'SELECT * FROM %n', $table['name']
  210. )
  211. ),
  212. ];
  213. $data = $this->processQueries($response);
  214. $this->setLoggerChannel('Migration')->info('Obtained Table data', ['table' => $table['name']]);
  215. foreach ($data as $row) {
  216. $response = [
  217. array(
  218. 'function' => 'query',
  219. 'query' => array(
  220. 'INSERT into %n', $table['name'],
  221. $row
  222. )
  223. ),
  224. ];
  225. $this->processQueries($response, true);
  226. }
  227. $this->setLoggerChannel('Migration')->info('Wrote Table data', ['table' => $table['name']]);
  228. }
  229. }
  230. if ($this->config['driver'] == 'mysqli') {
  231. $response = [
  232. array(
  233. 'function' => 'query',
  234. 'query' => array(
  235. 'DROP DATABASE IF EXISTS %n', $this->config['dbName']
  236. )
  237. ),
  238. ];
  239. $data = $this->processQueries($response);
  240. if ($data) {
  241. $create = $this->createNewDB($this->config['dbName']);
  242. if ($create) {
  243. $structure = $this->createDB($this->config['dbLocation']);
  244. if ($structure) {
  245. foreach ($tables as $table) {
  246. if (in_array($table['name'], $defaultTables)) {
  247. $response = [
  248. array(
  249. 'function' => 'fetchAll',
  250. 'query' => array(
  251. 'SELECT * FROM %n', $table['name']
  252. )
  253. ),
  254. ];
  255. $data = $this->processQueries($response, true);
  256. $this->setLoggerChannel('Migration')->info('Obtained Table data', ['table' => $table['name']]);
  257. foreach ($data as $row) {
  258. $response = [
  259. array(
  260. 'function' => 'query',
  261. 'query' => array(
  262. 'INSERT into %n', $table['name'],
  263. $row
  264. )
  265. ),
  266. ];
  267. $this->processQueries($response);
  268. }
  269. $this->setLoggerChannel('Migration')->info('Wrote Table data', ['table' => $table['name']]);
  270. }
  271. }
  272. } else {
  273. $this->setLoggerChannel('Migration')->warning('Could not recreate Database structure');
  274. }
  275. } else {
  276. $this->setLoggerChannel('Migration')->warning('Could not recreate Database');
  277. }
  278. } else {
  279. $this->setLoggerChannel('Migration')->warning('Could not drop old tempMigration Database');
  280. }
  281. $this->setLoggerChannel('Migration')->info('All Table data converted');
  282. @unlink($tempLock);
  283. return true;
  284. }
  285. //$this->db->disconnect();
  286. //$this->otherDb->disconnect();
  287. // Remove Current Database
  288. if ($this->config['driver'] == 'sqlite3') {
  289. $this->setLoggerChannel('Migration')->info('All Table data converted');
  290. $this->setLoggerChannel('Migration')->info('Starting Database movement for sqlite3');
  291. if (file_exists($this->config['dbLocation'] . $migrationDB)) {
  292. $oldFileSize = filesize($this->config['dbLocation'] . $this->config['dbName']);
  293. $newFileSize = filesize($this->config['dbLocation'] . $migrationDB);
  294. if ($newFileSize > 0) {
  295. $this->setLoggerChannel('Migration')->info('New Table size has been verified');
  296. @unlink($this->config['dbLocation'] . $this->config['dbName']);
  297. copy($this->config['dbLocation'] . $migrationDB, $this->config['dbLocation'] . $this->config['dbName']);
  298. @unlink($this->config['dbLocation'] . $migrationDB);
  299. $this->setLoggerChannel('Migration')->info('Migrated Old Info to new Database');
  300. @unlink($tempLock);
  301. return true;
  302. } else {
  303. $this->setLoggerChannel('Migration')->warning('Database filesize is zero');
  304. }
  305. } else {
  306. $this->setLoggerChannel('Migration')->warning('Migration Database does not exist');
  307. }
  308. }
  309. @unlink($tempLock);
  310. return false;
  311. } else {
  312. $this->setLoggerChannel('Migration')->warning('Could not create migration Database');
  313. }
  314. @unlink($tempLock);
  315. return false;
  316. }
  317. return false;
  318. }
  319. public function upgradeToVersion($version = '2.1.0')
  320. {
  321. switch ($version) {
  322. case '2.1.0':
  323. $this->upgradeSettingsTabURL();
  324. $this->upgradeHomepageTabURL();
  325. case '2.1.400':
  326. $this->removeOldPluginDirectoriesAndFiles();
  327. case '2.1.525':
  328. $this->removeOldCustomHTML();
  329. case '2.1.860':
  330. $this->upgradeInstalledPluginsConfigItem();
  331. case '2.1.1500':
  332. $this->upgradeDataToFolder();
  333. default:
  334. $this->setAPIResponse('success', 'Ran update function for version: ' . $version, 200);
  335. return true;
  336. }
  337. }
  338. public function removeOldCacheFolder()
  339. {
  340. $folder = $this->root . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  341. $this->setLoggerChannel('Migration');
  342. $this->logger->info('Running Old Cache folder migration');
  343. if (file_exists($folder)) {
  344. $this->rrmdir($folder);
  345. $this->logger->info('Old Cache folder found');
  346. $this->logger->info('Removed Old Cache folder');
  347. }
  348. return true;
  349. }
  350. public function upgradeDataToFolder()
  351. {
  352. if ($this->hasDB()) {
  353. // Make main data folder
  354. $rootFolderMade = $this->makeDir($this->root . DIRECTORY_SEPARATOR . 'data');
  355. // Make config folder child
  356. $this->makeDir($this->root . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR);
  357. if ($rootFolderMade) {
  358. // Migrate over userTabs folder
  359. $this->makeDir($this->root . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'userTabs');
  360. if ($this->rcopy($this->root . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'userTabs', $this->root . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'userTabs')) {
  361. // Convert tabs over
  362. $query = [
  363. [
  364. 'function' => 'fetchAll',
  365. 'query' => [
  366. 'SELECT * FROM tabs WHERE image like "%userTabs%"'
  367. ]
  368. ],
  369. ];
  370. $tabs = $this->processQueries($query);
  371. if (count($tabs) > 0) {
  372. foreach ($tabs as $tab) {
  373. $newImage = str_replace('plugins/images/userTabs', 'data/userTabs', $tab['image']);
  374. $updateQuery = [
  375. [
  376. 'function' => 'query',
  377. 'query' => [
  378. 'UPDATE tabs SET',
  379. ['image' => $newImage],
  380. 'WHERE id = ?',
  381. $tab['id']
  382. ]
  383. ],
  384. ];
  385. $this->processQueries($updateQuery);
  386. }
  387. }
  388. $this->setLoggerChannel('Migration');
  389. $this->logger->info('The folder "userTabs" was migrated to new data folder');
  390. }
  391. // Migrate over custom cert
  392. if (file_exists($this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'functions' . DIRECTORY_SEPARATOR . 'cert' . DIRECTORY_SEPARATOR . 'custom.pem')) {
  393. // Make cert folder child
  394. $this->makeDir($this->root . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'cert' . DIRECTORY_SEPARATOR);
  395. if ($this->rcopy($this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'functions' . DIRECTORY_SEPARATOR . 'cert' . DIRECTORY_SEPARATOR . 'custom.pem', $this->root . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'cert' . DIRECTORY_SEPARATOR . 'custom.pem')) {
  396. $this->setLoggerChannel('Migration');
  397. $this->logger->info('Moved over custom cert file');
  398. }
  399. }
  400. // Migrate over favIcon
  401. $this->makeDir($this->root . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'favicon');
  402. if ($this->rcopy($this->root . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'faviconCustom', $this->root . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'favicon')) {
  403. if ($this->config['favIcon'] !== '') {
  404. $this->config['favIcon'] = str_replace('plugins/images/faviconCustom', 'data/favicon', $this->config['favIcon']);
  405. $this->updateConfig(array('favIcon' => $this->config['favIcon']));
  406. }
  407. $this->setLoggerChannel('Migration');
  408. $this->logger->info('Favicon was migrated over');
  409. }
  410. // Migrate over custom pages
  411. $this->makeDir($this->root . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'pages');
  412. if (file_exists($this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'pages' . DIRECTORY_SEPARATOR . 'custom')) {
  413. if ($this->rcopy($this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'pages' . DIRECTORY_SEPARATOR . 'custom', $this->root . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'pages')) {
  414. $this->rrmdir($this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'pages' . DIRECTORY_SEPARATOR . 'custom');
  415. $this->setLoggerChannel('Migration');
  416. $this->logger->info('Custom pages was migrated over');
  417. }
  418. }
  419. // Migrate over custom routes
  420. $this->makeDir($this->root . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'routes');
  421. if (file_exists($this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'v2' . DIRECTORY_SEPARATOR . 'routes' . DIRECTORY_SEPARATOR . 'custom')) {
  422. if ($this->rcopy($this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'v2' . DIRECTORY_SEPARATOR . 'routes' . DIRECTORY_SEPARATOR . 'custom', $this->root . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'routes')) {
  423. $this->rrmdir($this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'v2' . DIRECTORY_SEPARATOR . 'routes' . DIRECTORY_SEPARATOR . 'custom');
  424. $this->setLoggerChannel('Migration');
  425. $this->logger->info('Custom routes was migrated over');
  426. }
  427. }
  428. // Migrate over cache folder
  429. $this->removeOldCacheFolder();
  430. }
  431. return true;
  432. }
  433. return false;
  434. }
  435. public function upgradeSettingsTabURL()
  436. {
  437. $response = [
  438. array(
  439. 'function' => 'query',
  440. 'query' => array(
  441. 'UPDATE tabs SET',
  442. ['url' => 'api/v2/page/settings'],
  443. 'WHERE url = ?',
  444. 'api/?v1/settings/page'
  445. )
  446. ),
  447. ];
  448. return $this->processQueries($response);
  449. }
  450. public function upgradeHomepageTabURL()
  451. {
  452. $response = [
  453. array(
  454. 'function' => 'query',
  455. 'query' => array(
  456. 'UPDATE tabs SET',
  457. ['url' => 'api/v2/page/homepage'],
  458. 'WHERE url = ?',
  459. 'api/?v1/homepage/page'
  460. )
  461. ),
  462. ];
  463. return $this->processQueries($response);
  464. }
  465. public function upgradeInstalledPluginsConfigItem()
  466. {
  467. $oldConfigItem = $this->config['installedPlugins'];
  468. if (gettype($oldConfigItem) == 'string') {
  469. if ((strpos($oldConfigItem, '|') !== false)) {
  470. $newPlugins = [];
  471. $plugins = explode('|', $oldConfigItem);
  472. foreach ($plugins as $plugin) {
  473. $info = explode(':', $plugin);
  474. $newPlugins[$info[0]] = [
  475. 'name' => $info[0],
  476. 'version' => $info[1],
  477. 'repo' => 'organizr'
  478. ];
  479. }
  480. } else {
  481. $newPlugins = [];
  482. if ($oldConfigItem !== '') {
  483. $info = explode(':', $oldConfigItem);
  484. $newPlugins[$info[0]] = [
  485. 'name' => $info[0],
  486. 'version' => $info[1],
  487. 'repo' => 'https://github.com/Organizr/Organizr-Plugins'
  488. ];
  489. }
  490. }
  491. $this->updateConfig(['installedPlugins' => $newPlugins]);
  492. } elseif (gettype($oldConfigItem) == 'array') {
  493. $this->updateConfig(['installedPlugins' => $oldConfigItem]);
  494. }
  495. return true;
  496. }
  497. public function removeOldPluginDirectoriesAndFiles()
  498. {
  499. $folders = [
  500. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'api',
  501. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'config',
  502. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'css',
  503. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'js',
  504. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'misc',
  505. ];
  506. $files = [
  507. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'bookmark.php',
  508. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'chat.php',
  509. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'healthChecks.php',
  510. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'invites.php',
  511. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'php-mailer.php',
  512. $this->root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'speedTest.php',
  513. ];
  514. foreach ($files as $file) {
  515. if (file_exists($file)) {
  516. @unlink($file);
  517. }
  518. }
  519. foreach ($folders as $folder) {
  520. if (file_exists($folder)) {
  521. @$this->rrmdir($folder);
  522. }
  523. }
  524. return true;
  525. }
  526. public function checkForConfigKeyAddToArray($keys)
  527. {
  528. $updateItems = [];
  529. foreach ($keys as $new => $old) {
  530. if (isset($this->config[$old])) {
  531. if ($this->config[$old] !== '') {
  532. $updateItemsNew = [$new => $this->config[$old]];
  533. $updateItems = array_merge($updateItems, $updateItemsNew);
  534. }
  535. }
  536. }
  537. return $updateItems;
  538. }
  539. public function removeOldCustomHTML()
  540. {
  541. $backup = $this->backupOrganizr();
  542. if ($backup) {
  543. $keys = [
  544. 'homepageCustomHTML01Enabled' => 'homepageCustomHTMLoneEnabled',
  545. 'homepageCustomHTML01Auth' => 'homepageCustomHTMLoneAuth',
  546. 'customHTML01' => 'customHTMLone',
  547. 'homepageCustomHTML02Enabled' => 'homepageCustomHTMLtwoEnabled',
  548. 'homepageCustomHTML02Auth' => 'homepageCustomHTMLtwoAuth',
  549. 'customHTML02' => 'customHTMLtwo',
  550. ];
  551. $updateItems = $this->checkForConfigKeyAddToArray($keys);
  552. $updateComplete = false;
  553. if (!empty($updateItems)) {
  554. $updateComplete = $this->updateConfig($updateItems);
  555. }
  556. if ($updateComplete) {
  557. $removeConfigItems = $this->removeConfigItem(['homepagCustomHTMLoneAuth', 'homepagCustomHTMLoneEnabled', 'homepagCustomHTMLtwoAuth', 'homepagCustomHTMLtwoEnabled', 'homepageOrdercustomhtml', 'homepageOrdercustomhtmlTwo', 'homepageCustomHTMLoneEnabled', 'homepageCustomHTMLoneAuth', 'customHTMLone', 'homepageCustomHTMLtwoEnabled', 'homepageCustomHTMLtwoAuth', 'customHTMLtwo']);
  558. if ($removeConfigItems) {
  559. return true;
  560. }
  561. }
  562. }
  563. return false;
  564. }
  565. }