示例#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);
 }
示例#3
0
 /**
  * Test recursive copying of directories
  *
  *
  */
 public function testRCopy()
 {
     $name = $this->_get_rand_name();
     $source_dir = dirname(dirname(__FILE__)) . '/model/samples/repo1';
     $target_dir = MODX_CORE_PATH . 'cache/repoman/' . $name;
     Repoman::rcopy($source_dir, $target_dir, array());
     $this->assertTrue(file_exists($target_dir . '/elements') && is_dir($target_dir . '/elements'), 'elements directory must exist');
     $this->assertTrue(file_exists($target_dir . '/elements/plugins') && is_dir($target_dir . '/elements/plugins'), 'elements/plugins directory must exist');
     $this->assertTrue(file_exists($target_dir . '/elements/snippets') && is_dir($target_dir . '/elements/snippets'), 'elements/snippets directory must exist');
     $this->assertTrue(file_exists($target_dir . '/elements/templates') && is_dir($target_dir . '/elements/templates'), 'elements/templates directory must exist');
     $this->assertTrue(file_exists($target_dir . '/elements/tvs') && is_dir($target_dir . '/elements/tvs'), 'elements/tvs directory must exist');
     $this->assertTrue(file_exists($target_dir . '/elements/chunks/MyChunk.html'), 'elements/chunks/MyChunk.html file must exist');
     $this->assertTrue(file_exists($target_dir . '/elements/plugins/MyPlugin.php'), 'elements/plugins/MyPlugin.php file must exist');
     $this->assertTrue(file_exists($target_dir . '/elements/snippets/MySnippet.php'), 'elements/snippets/MySnippet.php file must exist');
     $this->assertTrue(file_exists($target_dir . '/elements/templates/MyTemplate.html'), 'elements/templates/MyTemplate.html file must exist');
     $this->assertTrue(file_exists($target_dir . '/elements/tvs/myTV.php'), 'elements/tvs/myTV.php file must exist');
     Repoman::rrmdir($target_dir);
 }
示例#4
0
 /**
  * Attempts to uninstall the default namespace, system settings, modx objects,
  * and any database migrations. The behavior is dependent on the MODX cache b/c
  * all new objects are registered in the repoman custom cache partition.
  *
  * No input parameters are required: this looks at the "namespace" config setting.
  *
  * php repoman.php uninstall --namespace=something
  */
 public function uninstall($pkg_root_dir)
 {
     $pkg_root_dir = self::get_dir($pkg_root_dir);
     // uninstall migrations. Global $modx and $object variables
     $this->migrate($pkg_root_dir, 'uninstall');
     // Remove installed objects
     $cache_dir = MODX_CORE_PATH . 'cache/repoman/' . $this->get('namespace');
     if (file_exists($cache_dir) && is_dir($cache_dir)) {
         $obj_dirs = array_diff(scandir($cache_dir), array('..', '.'));
         foreach ($obj_dirs as $objectname_dir) {
             if (!is_dir($cache_dir . '/' . $objectname_dir)) {
                 continue;
                 // wtf? Did you manually edit the cache dirs?
             }
             $objects = array_diff(scandir($cache_dir . '/' . $objectname_dir), array('..', '.'));
             $objecttype = basename($objectname_dir);
             foreach ($objects as $o) {
                 $criteria = (include $cache_dir . '/' . $objectname_dir . '/' . $o);
                 $Obj = $this->modx->getObject($objecttype, $criteria);
                 if ($Obj) {
                     $Obj->remove();
                 } else {
                     // Some objects are removed b/c of relations before we get to them
                     $this->modx->log(modX::LOG_LEVEL_DEBUG, $objecttype . ' could not be located ' . print_r($criteria, true));
                 }
             }
         }
         Repoman::rrmdir($cache_dir);
     } else {
         $this->modx->log(modX::LOG_LEVEL_WARN, 'No cached import data at ' . $cache_dir);
     }
     $this->tidy_modx();
 }
示例#5
0
 /**
  * Any specific processing we want to do here. Return a string of html.
  *
  * @param array $scriptProperties
  *
  * @return string
  */
 public function process(array $scriptProperties = array())
 {
     $this->props['pagetitle'] = 'Overview';
     $pagedata = array('repo_dir_settings' => '', 'cache_settings' => '', 'repos' => '', 'error' => false);
     $props = array();
     // Listen specifically for POST (poor-man's routing here...)
     if (!empty($_POST)) {
         if (!($Setting = $this->modx->getObject('modSystemSetting', array('key' => 'repoman.dir')))) {
             $Setting = $this->modx->newObject('modSystemSetting');
             $Setting->set('key', 'repoman.dir');
         }
         $Setting->set('value', $this->modx->getOption('repoman_dir', $_POST, ''));
         $Setting->save();
         $this->modx->setOption('repoman.dir', $this->modx->getOption('repoman_dir', $_POST, ''));
         $this->modx->cacheManager->refresh(array('system_settings' => array()));
     }
     /*
     ----------------
     Repo Dir Setting
     ----------------
     */
     $this->props['class'] = 'repoman_success';
     $repo_dir = $this->modx->getOption('repoman.dir');
     if (empty($repo_dir)) {
         $this->props['class'] = 'repoman_error';
         $this->props['msg'] = $this->_get_msg('Set your Repoman directory (relative to your MODx base path) so Repoman will know where to find your local repositories.', 'error');
         $pagedata['error'] = true;
     } elseif (!file_exists(MODX_BASE_PATH . $repo_dir)) {
         $this->props['class'] = 'repoman_error';
         $this->props['msg'] = $this->_get_msg($repo_dir . ' does not exist!', 'error');
         $pagedata['error'] = true;
     } elseif (!is_dir(MODX_BASE_PATH . $repo_dir)) {
         $this->props['class'] = 'repoman_error';
         $this->props['msg'] = $this->_get_msg($repo_dir . ' must be a directory!', 'error');
         $pagedata['error'] = true;
     } elseif ($repo_dir == MODX_CONNECTORS_URL || $repo_dir == MODX_MANAGER_URL || $repo_dir == 'core/') {
         $this->props['class'] = 'repoman_error';
         $this->props['msg'] = $this->_get_msg($repo_dir . ' cannot be one of the built-in MODX directories.', 'error');
         $pagedata['error'] = true;
     } else {
         $repos = '';
         $i = 0;
         foreach (new RecursiveDirectoryIterator(MODX_BASE_PATH . $repo_dir) as $filename) {
             if (!is_dir($filename)) {
                 continue;
             }
             $shortname = basename($filename);
             if ($shortname == '.' || $shortname == '..') {
                 continue;
             }
             $i++;
             $class = 'repoman_odd';
             if ($i % 2 == 0) {
                 $class = 'repoman_even';
             }
             try {
                 $config = Repoman::load_config($filename);
                 $repos .= $this->_load('tr_repo', array('install_link' => $this->getUrl('install', array('repo' => $shortname)), 'view_link' => $this->getUrl('view', array('repo' => $shortname)), 'package_name' => $config['package_name'], 'description' => $config['description'], 'class' => $class, 'namespace' => $config['namespace'], 'subdir' => $shortname));
             } catch (Exception $e) {
                 $repos .= $this->_load('tr_repo_error', array('package_name' => $config['package_name'], 'class' => $class, 'package_name' => $shortname, 'error' => '<code>' . $e->getMessage() . '</code>', 'subdir' => $shortname));
             }
         }
     }
     // Repos
     if (empty($repos)) {
         $pagedata['repos'] = $this->_get_msg('You do not have any repos in your repo directory yet.', 'warning');
     } else {
         $pagedata['repos'] .= $this->_load('table', array('content' => $repos, 'class' => 'repos'));
     }
     $this->props['content'] = $this->_load('page_index', $pagedata);
     return $this->_render();
 }