示例#1
0
 public function uninstall()
 {
     $this->load->language('extension/installer');
     $json = array();
     $addon_lib = new Addon($this->registry);
     $addon = $addon_lib->getAddon($this->request->get['product_id']);
     if (empty($addon)) {
         $json['error'] = $this->language->get('error_uninstall_already');
     }
     if (!$json) {
         $files = json_decode($addon['addon_files']);
         // Fire event
         $this->trigger->fire('pre.admin.extension.uninstall', $files);
         $absolutePaths = $codes = array();
         foreach ($files as $file) {
             $absolutePaths[] = DIR_ROOT . $file;
         }
         // Remove files
         $this->filesystem->remove($absolutePaths);
         $params = json_decode($addon['params'], true);
         if (count($params) and $addon['product_type'] == 'translation') {
             $this->load->model('localisation/language');
             foreach ($params['localisation/language'] as $id) {
                 $lang = $this->model_localisation_language->getLanguage($id);
                 if (isset($lang['directory'])) {
                     $this->filesystem->remove(array(DIR_ROOT . 'admin/language/' . $lang['directory'], DIR_ROOT . 'catalog/language/' . $lang['directory']));
                 }
             }
         }
         // Remove addon and its related row from tables
         $addon_lib->removeAddon($this->request->get['product_id']);
         if (count($params)) {
             foreach ($params as $model => $foreign_ids) {
                 $this->load->model($model);
                 $array = explode('/', $model);
                 $function_name = 'delete' . ucfirst($array[1]);
                 $model = 'model_' . implode('_', $array);
                 foreach ($foreign_ids as $foreign_id) {
                     $this->{$model}->{$function_name}($foreign_id);
                 }
             }
         }
         // Refresh modifications
         $this->request->get['extensionInstaller'] = 1;
         $this->load->controller('extension/modification/refresh');
         unset($this->request->get['extensionInstaller']);
         $json['success'] = $this->language->get('text_uninstall_success');
         unset($this->session->data['addon_params']);
         $this->cache->remove('addon');
         $this->cache->remove('update');
         $this->cache->remove('version');
     }
     $this->response->addHeader('Content-Type: application/json');
     $this->response->setOutput(json_encode($json));
 }