コード例 #1
0
 public function uploadAction()
 {
     $root = Shopware()->Container()->getParameter('kernel.root_dir');
     $root .= '/engine/Shopware/Plugins/Community';
     if (!is_writable($root)) {
         $this->View()->assign(['success' => false, 'message' => 'Plugin Community directory is not writable']);
         return;
     }
     try {
         $fileBag = new FileBag($_FILES);
         /** @var $file UploadedFile */
         $file = $fileBag->get('plugin');
     } catch (Exception $e) {
         $this->View()->assign(['success' => false, 'message' => $e->getMessage()]);
         return;
     }
     $information = pathinfo($file->getClientOriginalName());
     if ($information['extension'] !== 'zip') {
         $this->View()->assign(['success' => false, 'message' => 'Wrong archive extension %s. Zip archive expected']);
         unlink($file->getPathname());
         unlink($file);
         return;
     }
     $name = $information['basename'];
     $path = $root . '/' . $name;
     try {
         $file->move($root, $name);
         $extractor = new PluginExtractor();
         $extractor->extract($path, $root);
         unlink($path);
         unlink($file->getPathname());
         unlink($file);
     } catch (Exception $e) {
         $this->View()->assign(['success' => false, 'message' => $e->getMessage()]);
         unlink($path);
         unlink($file->getPathname());
         unlink($file);
         $this->View()->assign(['success' => false, 'message' => $e->getMessage()]);
         return;
     }
     $this->View()->assign('success', true);
 }
コード例 #2
0
 /**
  * @param $file
  * @param $pluginName
  * @throws \Exception
  */
 public function extractPluginZip($file, $pluginName)
 {
     $source = $this->getPluginSource($pluginName);
     if (!$source) {
         $source = 'Community';
     }
     $destination = $this->rootDir . '/engine/Shopware/Plugins/' . $source;
     $extractor = new PluginExtractor();
     $extractor->extract($file, $destination);
 }