Ejemplo n.º 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);
 }
Ejemplo n.º 2
0
 /**
  * Big and important... make sure this stuff gets loaded correctly.
  */
 public function testImport()
 {
     if ($Chunk = self::$modx->getObject('modChunk', array('name' => 'test_pkg6'))) {
         $Chunk->remove();
     }
     if ($Snippet = self::$modx->getObject('modSnippet', array('name' => 'test_pkg6'))) {
         $Snippet->remove();
     }
     if ($Plugin = self::$modx->getObject('modPlugin', array('name' => 'test_pkg6'))) {
         $Plugin->remove();
     }
     if ($Template = self::$modx->getObject('modTemplate', array('templatename' => 'test_template_pkg6'))) {
         $Template->remove();
     }
     if ($TV = self::$modx->getObject('modTemplateVar', array('name' => 'test_pkg6'))) {
         $TV->remove();
     }
     self::$modx->setOption('repoman.dir', dirname(__FILE__) . '/repos/');
     // prob'ly not req'd
     $pkg_root = dirname(__FILE__) . '/repos/pkg6/';
     $config = Repoman::load_config($pkg_root);
     $Repoman = new Repoman(self::$modx, $config);
     //$Repoman->prep_modx($pkg_root);
     $Repoman->install($pkg_root);
     $Chunk = self::$modx->getObject('modChunk', array('name' => 'test_pkg6'));
     $this->assertTrue(is_object($Chunk), 'Chunk should have been imported.');
     $this->assertTrue($Chunk->get('description') == "C'mon Barbie let's go party", 'Chunk should have been imported.');
     $this->assertTrue(strpos($Chunk->getContent(), 'This is a test chunk.') !== false, 'Chunk should have been imported.');
     $Snippet = self::$modx->getObject('modSnippet', array('name' => 'test_pkg6'));
     $this->assertTrue(is_object($Snippet), 'Snippet should have been imported.');
     $this->assertTrue($Snippet->get('description') == "Let me make you some coffee", 'Snippet should have been imported.');
     $this->assertTrue(strpos($Snippet->getContent(), "return date('Y-m-d H:i:s');") !== false, 'Snippet should have been imported.');
     $Plugin = self::$modx->getObject('modPlugin', array('name' => 'test_pkg6'));
     $this->assertTrue(is_object($Plugin), 'Plugin should have been imported.');
     $this->assertTrue($Plugin->get('description') == "Ladies and Gentlemen...", 'Plugin should have been imported.');
     $this->assertTrue(strpos($Plugin->getContent(), "return date('Y-m-d H:i:s');") !== false, 'Plugin should have been imported.');
     if ($Events = $Plugin->getMany('PluginEvents')) {
         foreach ($Events as $E) {
             $this->assertTrue($E->get('event') == 'OnPageNotFound', 'Plugin Events should have been imported.');
         }
     }
     $this->assertTrue(is_array($Events), 'Plugin should have events attached.');
     $TV = self::$modx->getObject('modTemplateVar', array('name' => 'test_pkg6'));
     $this->assertTrue(is_object($TV), 'TV should have been imported.');
     $this->assertTrue($TV->get('description') == "Now that is a Kankle", 'TV should have been imported.');
     $Template = self::$modx->getObject('modTemplate', array('templatename' => 'test_template_pkg6'));
     $this->assertTrue(is_object($Template), 'Template should have been imported.');
     $this->assertTrue($Template->get('description') == 'Gnar gnar description', 'Template should have been imported.');
     $this->assertTrue(strpos($Template->getContent(), 'This is my template.') !== false, 'Template should have been imported.');
     if ($TVTs = $Template->getMany('TemplateVarTemplates')) {
         foreach ($TVTs as $t) {
             if ($TVs = $t->getMany('TemplateVar')) {
                 foreach ($TVs as $tv) {
                     $this->assertTrue($tv->get('name') == 'test_pkg6', 'TV should have been imported.');
                 }
             }
         }
     }
     // Cleanup
     if ($Chunk) {
         $Chunk->remove();
     }
     if ($Snippet) {
         $Snippet->remove();
     }
     if ($Plugin) {
         $Plugin->remove();
     }
     if ($Template) {
         $Template->remove();
     }
     if ($TV) {
         $TV->remove();
     }
     $Repoman->tidy_modx();
 }