cleanup.class.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Processor file for UpgradeMODX extra
  4. *
  5. * Copyright 2015-2018 by Bob Ray <https://bobsguides.com>
  6. * Created on 07-16-2018
  7. *
  8. * UpgradeMODX is free software; you can redistribute it and/or modify it under the
  9. * terms of the GNU General Public License as published by the Free Software
  10. * Foundation; either version 2 of the License, or (at your option) any later
  11. * version.
  12. *
  13. * UpgradeMODX is distributed in the hope that it will be useful, but WITHOUT ANY
  14. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  15. * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * UpgradeMODX; if not, write to the Free Software Foundation, Inc., 59 Temple
  19. * Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. * @package upgrademodx
  22. * @subpackage processors
  23. */
  24. /* @var $modx modX */
  25. include_once 'ugmprocessor.class.php';
  26. class UpgradeMODXCleanupProcessor extends UgmProcessor {
  27. public $languageTopics = array('upgrademodx:default');
  28. function initialize() {
  29. /* Initialization here */
  30. parent::initialize();
  31. $this->name = 'Cleanup Processor';
  32. $this->log($this->modx->lexicon('ugm_deleting_temp_files'));
  33. return true;
  34. }
  35. /**
  36. * Copy root config.core.php to setup/includes
  37. * after adding setup key
  38. * @throws Exception
  39. */
  40. /* ToDo: Add option to save downloaded .zip file */
  41. public function cleanUp() {
  42. $rootCoreConfig = $this->basePath . 'config.core.php';
  43. $success = true;
  44. if (!$this->customTempDir) {
  45. $this->rrmdir($this->tempDir);
  46. } else {
  47. $this->rrmdir($this->unzippedDir);
  48. }
  49. }
  50. /** Recursive remove dir function.
  51. * Removes a directory and all its children */
  52. public function rrmdir($dir) {
  53. $dir = rtrim($dir, '/\\');
  54. if (is_dir($dir)) {
  55. $objects = scandir($dir);
  56. foreach ($objects as $object) {
  57. if ($object != "." && $object != "..") {
  58. if (filetype($dir . "/" . $object) == "dir") {
  59. $prefix = substr($object, 0, 4);
  60. $this->rrmdir($dir . "/" . $object);
  61. } else {
  62. @unlink($dir . "/" . $object);
  63. }
  64. }
  65. }
  66. reset($objects);
  67. $success = @rmdir($dir);
  68. }
  69. }
  70. public function process() {
  71. try{
  72. $this->cleanUp();
  73. } catch (Exception $e) {
  74. $this->addError($e->getMessage());
  75. }
  76. if (! $this->hasErrors()) {
  77. $this->log($this->modx->lexicon('ugm_temp_files_deleted'));
  78. $this->log($this->modx->lexicon('ugm_launching_setup'));
  79. }
  80. return $this->prepareResponse($this->modx->lexicon('ugm_launching_setup'));
  81. }
  82. }
  83. return 'UpgradeMODXCleanupProcessor';