Example #1
0
 /**
  * 1. Detects URL or github user/repo or composer package
  * 2. Downloads
  * 3. Installs extension
  * 4. Activates extension
  *
  * Composer: ./Console/cake install plugin vendor/package
  * Github: ./Console/cake install plugin user repo
  * Url: ./Console/cake install plugin https://github.com/user/repo
  */
 public function main()
 {
     $type = $this->args[0];
     if (strpos($this->args[1], '/') !== false && preg_match('/http[s]*:\\/\\//i', $this->args[1]) === 0) {
         // Composer Install
         $ver = isset($this->args[2]) ? $this->args[2] : '*';
         $this->out(__('Installing with Composer...'));
         try {
             $result = $this->_ExtensionsInstaller->composerInstall(array('package' => $this->args[1], 'version' => $ver, 'type' => $type));
             if (!is_array($result)) {
                 $this->err(__('Unexpected composerInstall return value'));
                 return false;
             }
             if ($result['returnValue'] != 0) {
                 $this->err($result['output']);
                 return false;
             }
             $ext = substr($this->args[1], strpos($this->args[1], '/') + 1);
             $ext = Inflector::camelize($ext);
             $shouldActivate = $this->{'_Croogo' . ucfirst($type)}->getData($ext);
             if ($shouldActivate !== false) {
                 $result = $this->dispatchShell('ext', 'activate', $type, $ext, '--quiet');
                 if ($result) {
                     $this->out(__('Package installed and activated.'));
                 } else {
                     $this->err(__('Package installed but not activated.'));
                 }
             }
         } catch (CakeException $e) {
             $this->err($e->getMessage());
         }
     } else {
         // Github / URL Install
         $url = '';
         if (count($this->args) == 2) {
             $url = $this->args[1];
         } elseif (count($this->args) == 3) {
             $url = 'http://github.com/' . $this->args[1] . '/' . $this->args[2];
         }
         if ($zip = $this->_download($url)) {
             if ($this->_install($type, $zip)) {
                 if ($this->_activate($type, $zip)) {
                     $this->out(__('Extension installed and activated.'));
                 }
             }
         }
     }
 }
 /**
  * admin_add
  *
  * @return void
  */
 public function admin_add()
 {
     $this->set('title_for_layout', __('Upload a new plugin'));
     if (!empty($this->request->data)) {
         $file = $this->request->data['Plugin']['file'];
         unset($this->request->data['Plugin']['file']);
         $Installer = new ExtensionsInstaller();
         try {
             $Installer->extractPlugin($file['tmp_name']);
         } catch (CakeException $e) {
             $this->Session->setFlash($e->getMessage(), 'default', array('class' => 'error'));
             $this->redirect(array('action' => 'add'));
         }
         $this->redirect(array('action' => 'index'));
     }
 }
 /**
  * admin_add
  *
  * @return void
  */
 public function admin_add()
 {
     $this->set('title_for_layout', __d('croogo', 'Upload a new theme'));
     if (!empty($this->request->data)) {
         $file = $this->request->data['Theme']['file'];
         unset($this->request->data['Theme']['file']);
         $Installer = new ExtensionsInstaller();
         try {
             $Installer->extractTheme($file['tmp_name']);
             $this->Session->setFlash(__d('croogo', 'Theme uploaded successfully.'), 'flash', array('class' => 'success'));
         } catch (CakeException $e) {
             $this->Session->setFlash($e->getMessage(), 'flash', array('class' => 'error'));
         }
         return $this->redirect(array('action' => 'index'));
     }
 }