Beispiel #1
0
 public function install_product($product_id)
 {
     $response = $this->communication->request('get_product_system_information', $product_id);
     if ($response->status != "success") {
         die("error");
     }
     @mkdir(APPPATH . 'download');
     $file = $this->communication->request_raw('download_product', $product_id);
     file_put_contents(APPPATH . "download/download.zip", $file);
     if (file_exists(APPPATH . "download/download.zip")) {
         PC::builder_market("Downloaded product zip.");
     } else {
         PC::builder_market("Unable to download product zip.");
     }
     $product = new Product();
     $product->remote_id = $response->info->product_id;
     $product->type = $response->info->type;
     $product->version = $response->info->version;
     $product->save();
     switch ($response->info->type) {
         case "theme":
             $zip = new ZipArchive();
             $file_path = APPPATH . "download/download.zip";
             if ($zip->open($file_path) === TRUE) {
                 $zip->extractTo(APPPATH . '../themes');
                 $zip->close();
                 unlink(APPPATH . "download/download.zip");
                 echo 'success';
             } else {
                 echo 'failed';
             }
             break;
         case "module":
             $zip = new ZipArchive();
             $file_path = APPPATH . "download/download.zip";
             if ($zip->open($file_path) === TRUE) {
                 $zip->extractTo(APPPATH . '../modules');
                 PC::builder_market("Zip extracted successfully.");
                 $folder = $zip->getNameIndex(0);
                 $folder = str_replace("/", "", $folder);
                 PC::builder_market("Unzipped folder " . $folder);
                 //$this->load->module('module_system/admin');
                 //$this->load->module('module_system');
                 //$this->module_system->admin->install();
                 echo Modules::run_with_params("module_system/install", array($folder));
                 $zip->close();
                 unlink(APPPATH . "download/download.zip");
                 echo "success";
             } else {
                 PC::builder_market("Unable to extract zip.");
                 echo 'failed';
             }
             break;
     }
 }