/** * 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); }
/** * */ public function testBuild() { $namespace = $this->_get_rand_name(); // Generate random version number $ver = rand(0, 100) . '.' . rand(0, 100) . '.' . rand(0, 100); $release = 'beta'; $pkg_root_dir = dirname(__FILE__) . '/repos/pkg8/'; $config = Repoman::load_config($pkg_root_dir); $config['namespace'] = $namespace; $config['package_name'] = $namespace; $config['version'] = $ver; $config['release'] = $release; $Repoman = new Repoman(self::$modx, $config); $Repoman->build($pkg_root_dir); $pkg = MODX_CORE_PATH . 'packages/' . $namespace . '-' . $ver . '-' . $release; $this->assertTrue(file_exists($pkg . '.transport.zip'), 'Building should have created a package: ' . $pkg . '.transport.zip'); $this->assertTrue(is_dir($pkg), 'Building should have created a package directory: ' . $pkg); // Check the manifest $this->assertTrue(file_exists($pkg . '/manifest.php'), 'Building should have created a manifest: ' . $pkg . '/manifest.php'); Repoman::rrmdir($pkg); unlink($pkg . '.transport.zip'); }
/** * 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(); }