1006.php (7226B)
1 <?php 2 class ModelUpgrade1006 extends Model { 3 public function upgrade() { 4 // Update some language settings 5 $this->db->query("UPDATE `" . DB_PREFIX . "setting` SET `value` = 'en-gb' WHERE `key` = 'config_language' AND `value` = 'en'"); 6 $this->db->query("UPDATE `" . DB_PREFIX . "setting` SET `value` = 'en-gb' WHERE `key` = 'config_admin_language' AND `value` = 'en'"); 7 $this->db->query("UPDATE `" . DB_PREFIX . "language` SET `code` = 'en-gb' WHERE `code` = 'en'"); 8 9 $this->cache->delete('language'); 10 11 // Update the template setting 12 $this->db->query("UPDATE `" . DB_PREFIX . "setting` SET `key` = 'config_theme', value = 'theme_default' WHERE `key` = 'config_template' AND `value` = 'default'"); 13 14 // Update the config.php by adding a DB_PORT 15 if (is_file(DIR_OPENCART . 'config.php')) { 16 $files = glob(DIR_OPENCART . '{config.php,admin/config.php}', GLOB_BRACE); 17 18 foreach ($files as $file) { 19 $upgrade = true; 20 21 $lines = file($file); 22 23 foreach ($lines as $line) { 24 if (strpos(strtoupper($line), 'DB_PORT') !== false) { 25 $upgrade = false; 26 27 break; 28 } 29 } 30 31 if ($upgrade) { 32 $output = ''; 33 34 foreach ($lines as $line_id => $line) { 35 if (strpos($line, 'DB_PREFIX') !== false) { 36 $output .= 'define(\'DB_PORT\', \'' . ini_get('mysqli.default_port') . '\');' . "\n"; 37 $output .= $line; 38 } else { 39 $output .= $line; 40 } 41 } 42 43 $handle = fopen($file, 'w'); 44 45 fwrite($handle, $output); 46 47 fclose($handle); 48 } 49 } 50 } 51 52 // Update the config.php to add /storage/ to paths 53 if (is_file(DIR_OPENCART . 'config.php')) { 54 $files = glob(DIR_OPENCART . '{config.php,admin/config.php}', GLOB_BRACE); 55 56 foreach ($files as $file) { 57 $upgrade = true; 58 59 $lines = file($file); 60 61 $output = ''; 62 63 foreach ($lines as $line_id => $line) { 64 $output .= $line; 65 } 66 67 $output = str_replace('system/modification', 'system/storage/modification', $output); 68 $output = str_replace('system/upload', 'system/storage/upload', $output); 69 $output = str_replace('system/logs', 'system/storage/logs', $output); 70 $output = str_replace('system/cache', 'system/storage/cache', $output); 71 72 // Since the download folder has had multiple locations, first set them all back to /download, then adjust to the new location 73 $output = str_replace('system/download', '/download', $output); 74 $output = str_replace('system/storage/download', '/download', $output); 75 $output = str_replace('/download', 'system/storage/download', $output); 76 77 $handle = fopen($file, 'w'); 78 79 fwrite($handle, $output); 80 81 fclose($handle); 82 } 83 } 84 85 // Disable any existing ocmods 86 $this->db->query("UPDATE `" . DB_PREFIX . "modification` SET status = 0"); 87 88 // Cleanup files in old directories 89 $directories = array( 90 DIR_SYSTEM . 'modification/', 91 DIR_SYSTEM . 'storage/modification/', 92 DIR_SYSTEM . 'logs/', 93 DIR_SYSTEM . 'cache/', 94 ); 95 96 $files = array(); 97 98 foreach ($directories as $dir) { 99 if (is_dir($dir)){ 100 // Make path into an array 101 $path = array($dir . '*'); 102 103 // While the path array is still populated keep looping through 104 while (count($path) != 0) { 105 $next = array_shift($path); 106 107 foreach (glob($next) as $file) { 108 // If directory add to path array 109 if (is_dir($file)) { 110 $path[] = $file . '/*'; 111 } 112 113 // Add the file to the files to be deleted array 114 $files[] = $file; 115 } 116 117 // Reverse sort the file array 118 rsort($files); 119 120 // Clear all modification files 121 foreach ($files as $file) { 122 if ($file != $dir . 'index.html') { 123 // If file just delete 124 if (is_file($file)) { 125 @unlink($file); 126 127 // If directory use the remove directory function 128 } elseif (is_dir($file)) { 129 @rmdir($file); 130 } 131 } 132 } 133 } 134 } 135 } 136 137 // Merge image/data to image/catalog 138 if (file_exists(DIR_IMAGE . 'data')) { 139 if (!file_exists(DIR_IMAGE . 'catalog')) { 140 rename(DIR_IMAGE . 'data', DIR_IMAGE . 'catalog'); // Rename data to catalog 141 } else { 142 $this->recursive_move(DIR_IMAGE . 'data', DIR_IMAGE . 'catalog'); 143 } 144 } 145 146 // Merge system/upload to system/storage/upload 147 if (file_exists(DIR_SYSTEM . 'upload')) { 148 $this->recursive_move(DIR_SYSTEM . 'upload', DIR_SYSTEM . 'storage/upload'); 149 } 150 151 // Merge download or system/download to system/storage/download 152 if (file_exists(DIR_OPENCART . 'download')) { 153 $this->recursive_move(DIR_OPENCART . 'download', DIR_SYSTEM . 'storage/download'); 154 } 155 156 if (file_exists(DIR_SYSTEM . 'download')) { 157 $this->recursive_move(DIR_SYSTEM . 'download', DIR_SYSTEM . 'storage/download'); 158 } 159 160 // Convert image/data to image/catalog 161 $this->db->query("UPDATE `" . DB_PREFIX . "banner_image` SET `image` = REPLACE (image , 'data/', 'catalog/')"); 162 $this->db->query("UPDATE `" . DB_PREFIX . "category` SET `image` = REPLACE (image , 'data/', 'catalog/')"); 163 $this->db->query("UPDATE `" . DB_PREFIX . "manufacturer` SET `image` = REPLACE (image , 'data/', 'catalog/')"); 164 $this->db->query("UPDATE `" . DB_PREFIX . "product` SET `image` = REPLACE (image , 'data/', 'catalog/')"); 165 $this->db->query("UPDATE `" . DB_PREFIX . "product_image` SET `image` = REPLACE (image , 'data/', 'catalog/')"); 166 $this->db->query("UPDATE `" . DB_PREFIX . "option_value` SET `image` = REPLACE (image , 'data/', 'catalog/')"); 167 $this->db->query("UPDATE `" . DB_PREFIX . "voucher_theme` SET `image` = REPLACE (image , 'data/', 'catalog/')"); 168 $this->db->query("UPDATE `" . DB_PREFIX . "setting` SET `value` = REPLACE (value , 'data/', 'catalog/')"); 169 $this->db->query("UPDATE `" . DB_PREFIX . "setting` SET `value` = REPLACE (value , 'data/', 'catalog/')"); 170 $this->db->query("UPDATE `" . DB_PREFIX . "product_description` SET `description` = REPLACE (description , 'data/', 'catalog/')"); 171 $this->db->query("UPDATE `" . DB_PREFIX . "category_description` SET `description` = REPLACE (description , 'data/', 'catalog/')"); 172 $this->db->query("UPDATE `" . DB_PREFIX . "information_description` SET `description` = REPLACE (description , 'data/', 'catalog/')"); 173 } 174 175 private function recursive_move($src, $dest){ 176 177 // If source is not a directory stop processing 178 if (!is_dir($src)) return false; 179 180 // If the destination directory does not exist create it 181 if(!is_dir($dest)) { 182 if(!@mkdir($dest)) { 183 // If the destination directory could not be created stop processing 184 return false; 185 } 186 } 187 188 // Open the source directory to read in files 189 $i = new DirectoryIterator($src); 190 foreach($i as $f) { 191 if($f->isFile() && !file_exists("$dest/" . $f->getFilename())) { 192 @rename($f->getRealPath(), "$dest/" . $f->getFilename()); 193 } elseif(!$f->isDot() && $f->isDir()) { 194 $this->recursive_move($f->getRealPath(), "$dest/$f"); 195 @unlink($f->getRealPath()); 196 } 197 } 198 199 // Remove source folder after move 200 @unlink($src); 201 } 202 }