示例#1
0
 /**
  * Any specific processing we want to do here. Return a string of html.
  * @param array $scriptProperties
  *      'namespace'
  *      'f' 
  */
 public function process(array $scriptProperties = array())
 {
     $namespace = $this->modx->getOption('namespace', $scriptProperties);
     $function = $this->modx->getOption('f', $scriptProperties);
     $response = array();
     $response['msg'] = '';
     $response['success'] = true;
     try {
         $dir = Repoman::get_dir(MODX_BASE_PATH . $this->modx->getOption('repoman.dir'));
         $pkg_root_dir = $dir . '/' . $namespace;
         $config = Repoman::load_config($pkg_root_dir);
         $Repoman = new Repoman($this->modx, $config);
         switch ($function) {
             case 'update':
                 $Repoman->update($pkg_root_dir);
                 $response['msg'] = $config['package_name'] . ' updated successfully to version ' . $config['version'] . '-' . $config['release'];
                 break;
             case 'install':
                 $Repoman->install($pkg_root_dir);
                 $response['msg'] = $config['package_name'] . ' installed successfully!';
                 break;
             case 'uninstall':
                 $Repoman->uninstall($pkg_root_dir);
                 $response['msg'] = $config['package_name'] . ' uninstalled successfully!';
                 break;
             case 'build':
                 $Repoman->build($pkg_root_dir);
                 $response['msg'] = $config['package_name'] . ' should have been built successfully.  Look inside the core/packages/ directory for the file. Please use the command line tool if you need to monitor the error log troubleshoot this process.';
                 break;
                 break;
             default:
                 $response['success'] = false;
                 $response['msg'] = 'Unknown function: ' . $function;
         }
     } catch (Exception $e) {
         $response['success'] = false;
         $response['msg'] = $e->getMessage();
     }
     return json_encode($response);
 }
 /**
  * Generate a series of links for the repo contained in the given $subdir
  *
  * @param string $subdir
  *
  * @return string
  */
 public function get_repo_links($subdir)
 {
     $data = array();
     $data['update_available'] = false;
     //        $data['repo'] = $subdir;
     $data['subdir'] = $subdir;
     try {
         $dir = Repoman::get_dir(MODX_BASE_PATH . $this->modx->getOption('repoman.dir'));
         $config = Repoman::load_config($dir . '/' . $subdir);
         $namespace = $config['namespace'] . '.version';
         $data['namespace'] = $config['namespace'];
         if (!($Setting = $this->modx->getObject('modSystemSetting', array('key' => $namespace)))) {
             $data['installed'] = false;
         } else {
             //print $Setting->get('value'); exit;
             //print $config['version']; exit;
             $data['installed'] = true;
             if (version_compare($Setting->get('value'), $config['version'], '<')) {
                 $data['update_available'] = true;
             }
         }
     } catch (Exception $e) {
         return $e->getMessage();
     }
     return $this->_load('links', $data);
 }