PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/oc-admin/upgrade.php

https://github.com/nsswaga/OSClass
PHP | 169 lines | 122 code | 28 blank | 19 comment | 35 complexity | 6b9308482c678c1756da82c63b5c1b5a MD5 | raw file
  1. <?php
  2. /*
  3. * OSCLass – software for creating and publishing online classified
  4. * advertising platforms
  5. *
  6. * Copyright (C) 2010 OSCLASS
  7. *
  8. * This program is free software: you can redistribute it and/or
  9. * modify it under the terms of the GNU Affero General Public License
  10. * as published by the Free Software Foundation, either version 3 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. define('ABS_PATH', dirname(dirname(__FILE__)) . '/');
  22. define('AUTO_UPGRADE', true);
  23. require_once ABS_PATH . 'oc-load.php';
  24. $action = Params::getParam('action');
  25. $message = "";
  26. switch($action) {
  27. case 'check-update':
  28. $message = __("Checking for update files");
  29. break;
  30. case 'download-file':
  31. if(Params::getParam('file')!='') {
  32. $tmp = explode("/", Params::getParam('file'));
  33. $filename = end($tmp);
  34. osc_downloadFile(Params::getParam('file'), $filename);
  35. $message = __('File downloaded correctly');
  36. } else {
  37. $message = __('Missing filename');
  38. }
  39. break;
  40. case 'empty-temp':
  41. $message = __("Removing temp-directory");
  42. $path = ABS_PATH . 'oc-temp';
  43. $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::CHILD_FIRST);
  44. for ($dir->rewind(); $dir->valid(); $dir->next()) {
  45. if ($dir->isDir()) {
  46. if($dir->getFilename()!='.' && $dir->getFilename()!='..') {
  47. rmdir($dir->getPathname());
  48. }
  49. } else {
  50. unlink($dir->getPathname());
  51. }
  52. }
  53. rmdir($path);
  54. break;
  55. case 'db-backup':
  56. osc_dbdump();
  57. break;
  58. case 'zip-osclass':
  59. $archive_name = ABS_PATH . "OSClass_backup.".date('YmdHis').".zip";
  60. $archive_folder = ABS_PATH;
  61. if (osc_zip_folder($archive_folder, $archive_name)) {
  62. $message = __('Archiving is sucessful!');
  63. } else {
  64. $message = __('Error, can\'t create a zip file!');
  65. }
  66. break;
  67. case 'unzip-file':
  68. if(Params::getParam('file')!='') {
  69. @mkdir(ABS_PATH.'oc-temp', 0777);
  70. $res = osc_unzip_file(osc_content_path() . 'downloads/' . Params::getParam('file'), ABS_PATH.'oc-temp/');
  71. if($res==1) {
  72. $message = __('OK');
  73. } else {
  74. $message = __('Unzip failed');
  75. }
  76. } else {
  77. $message = __('Filename incorrect');
  78. }
  79. break;
  80. case 'remove-files':
  81. if(file_exists(ABS_PATH.'oc-temp/remove.list')) {
  82. $lines = file(ABS_PATH.'oc-temp/remove.list', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  83. $message = "";
  84. foreach ($lines as $line_num => $r_file) {
  85. $unlink = @unlink(ABS_PATH.$r_file);
  86. if(!$unlink) { $message .= sprintf(__('Error removing file: %s'), $r_file) . "<br/>"; }
  87. }
  88. if($message=="") {
  89. $message = __('Files removed');
  90. }
  91. } else {
  92. $message = __('No files to remove');
  93. }
  94. break;
  95. case 'copy-files':
  96. $fail = -1;
  97. if ($handle = opendir(ABS_PATH.'oc-temp')) {
  98. $fail = 0;
  99. while (false !== ($_file = readdir($handle))) {
  100. if($_file!='.' && $_file!='..' && $_file!='remove.list' && $_file!='upgrade.sql' && $_file!='customs.actions') {
  101. $data = osc_copy(ABS_PATH."oc-temp/".$_file, ABS_PATH.$_file);
  102. if($data==false) {
  103. $fail = 1;
  104. };
  105. }
  106. }
  107. closedir($handle);
  108. if($fail==-1) {
  109. $message = __('Nothing to copy');
  110. } else if($fail==0) {
  111. $message = __('Files copied');
  112. } else {
  113. $message = __('There were problems copying files. Maybe the file permissions are not set correctly');
  114. }
  115. } else {
  116. $message = __('Nothing to copy');
  117. }
  118. break;
  119. case 'execute-sql':
  120. if(file_exists(osc_lib_path() . 'osclass/installer/struct.sql')) {
  121. $sql = file_get_contents(osc_lib_path() . 'osclass/installer/struct.sql');
  122. $conn = getConnection();
  123. $queries = $conn->osc_updateDB(str_replace('/*TABLE_PREFIX*/', DB_TABLE_PREFIX, $sql));
  124. $message = __('Tables updated correctly') ;
  125. } else {
  126. $message = __('No tables update to execute') ;
  127. }
  128. break ;
  129. case 'execute-actions':
  130. if(file_exists(osc_lib_path() . 'osclass/upgrade-funcs.php')) {
  131. require_once osc_lib_path() . 'osclass/upgrade-funcs.php';
  132. $message = __('Custom actions executed') ;
  133. } else {
  134. $message = __('No action to execute') ;
  135. }
  136. break ;
  137. default:
  138. osc_renderAdminSection('tools/upgrade.php', __('Update')) ;
  139. break ;
  140. }
  141. echo $message;