Example #1
0
 public function testGetConfig()
 {
     $instance = Teleport::instance(array('foo' => 'bar'));
     $config = $instance->getConfig();
     $this->assertInstanceOf('Teleport\\Config', $config);
     $this->assertEquals('bar', $config->get('foo'));
 }
Example #2
0
 public function process()
 {
     parent::process();
     try {
         $this->profile = Teleport::loadProfile($this->profile);
         if (empty($this->passwordnotifymethod)) {
             $this->passwordnotifymethod = 's';
         }
         if (!empty($this->password)) {
             $this->passwordgenmethod = '';
             $this->newpassword = $this->password;
             $this->specifiedpassword = $this->password;
             $this->confirmpassword = $this->password;
         }
         $this->getMODX($this->profile);
         $this->modx->getService('error', 'error.modError');
         $this->modx->error->message = '';
         $this->modx->setOption(\xPDO::OPT_SETUP, true);
         /** @var \modProcessorResponse $response */
         $response = $this->modx->runProcessor('security/user/create', $this->request->args());
         if ($response->isError()) {
             throw new ActionException($this, implode("\n", $response->getAllErrors()) . "\n0");
         } else {
             $this->request->log("Created user for {$this->profile->name} with username {$this->username}: {$response->getMessage()}");
         }
         $this->request->log('1', false);
     } catch (\Exception $e) {
         throw new ActionException($this, "Error creating MODX user: {$e->getMessage()}", $e);
     }
 }
Example #3
0
 public function process()
 {
     parent::process();
     try {
         $this->profile = Teleport::loadProfile($this->profile);
         $this->getMODX($this->profile);
         $this->modx->getService('error', 'error.modError');
         $this->modx->error->message = '';
         $this->modx->setOption(\xPDO::OPT_SETUP, true);
         $this->modx->loadClass('transport.xPDOTransport', XPDO_CORE_PATH, true, true);
         $this->modx->loadClass('transport.modTransportPackage');
         $latestPackages = $this->modx->call('modTransportPackage', 'listPackages', array(&$this->modx, 1));
         /** @var \modTransportPackage $latestPackage */
         foreach ($latestPackages['collection'] as $latestPackage) {
             $versions = $this->modx->call('modTransportPackage', 'listPackageVersions', array(&$this->modx, array('package_name:LIKE' => $latestPackage->package_name, 'signature:!=' => $latestPackage->signature)));
             if (isset($versions['collection']) && $versions['total'] > 0) {
                 $this->request->log("Removing {$versions['total']} outdated package versions for {$latestPackage->package_name}");
                 /** @var \modTransportPackage $version */
                 foreach ($versions['collection'] as $version) {
                     $this->request->log("Removing outdated package version {$version->signature} from {$this->profile->name}");
                     $version->removePackage(true, false);
                     $this->removePackageFiles($version->signature);
                 }
             }
         }
         $this->request->log("Completed Removing outdated packages for {$this->profile->name}");
     } catch (\Exception $e) {
         throw new ActionException($this, "Error removing outdated packages: {$e->getMessage()}", $e);
     }
 }
Example #4
0
 /**
  * Get a MODX reference to operate on.
  *
  * @param \stdClass $profile An object describing properties of a MODX
  * instance.
  *
  * @return \modX A reference to a MODX instance.
  */
 public function &getMODX($profile)
 {
     if (!$this->modx instanceof \modX) {
         $results = $this->request->getResults();
         $this->modx = Teleport::instance()->getMODX($profile, $this->request->args(), $results);
     }
     return $this->modx;
 }
Example #5
0
 /**
  * Process the Extract action.
  *
  * @throws ActionException If an error is encountered during processing.
  */
 public function process()
 {
     parent::process();
     try {
         $this->profile = Teleport::loadProfile($this->profile);
         $this->getMODX($this->profile);
         $this->tpl = $this->loadTpl($this->tpl);
         $this->package = $this->createPackage($this->getName(), $this->getVersion(), $this->getSequence());
         if (isset($this->tpl['attributes'])) {
             foreach ($this->tpl['attributes'] as $attribute => $attributeValue) {
                 if (is_array($attributeValue) && isset($attributeValue['sourceType']) && isset($attributeValue['source'])) {
                     switch ($attributeValue['sourceType']) {
                         case 'fileContent':
                             $attributeValue = file_get_contents($attributeValue['source']);
                             break;
                     }
                 }
                 $this->package->setAttribute($attribute, $attributeValue);
             }
         }
         foreach ($this->tpl['vehicles'] as $vehicle) {
             $this->createVehicles($vehicle);
         }
         if (!$this->package->pack()) {
             throw new ActionException($this, "Error packing {$this->package->signature}.transport.zip");
         }
         $this->request->log("Successfully extracted {$this->package->signature}.transport.zip from instance {$this->profile->code}");
         if ($this->target && $this->push) {
             if (!$this->push($this->package->path . $this->package->signature . '.transport.zip', $this->target . $this->package->signature . '.transport.zip')) {
                 throw new ActionException($this, "Error pushing {$this->package->signature}.transport.zip to {$this->target}");
             }
             if (!$this->preserveWorkspace && $this->modx->getCacheManager()) {
                 $this->modx->cacheManager->deleteTree($this->package->path . $this->package->signature);
                 @unlink($this->package->path . $this->package->signature . '.transport.zip');
             }
             $this->request->log("Successfully pushed {$this->package->signature}.transport.zip to {$this->target}");
             $this->request->log("{$this->target}{$this->package->signature}.transport.zip", false);
         } else {
             $this->request->log("{$this->package->path}{$this->package->signature}.transport.zip", false);
         }
     } catch (\Exception $e) {
         throw new ActionException($this, "Error Extracting snapshot: " . $e->getMessage(), $e);
     }
 }
Example #6
0
 /**
  * Process the Inject action.
  *
  * @throws ActionException If an error is encountered during processing.
  */
 public function process()
 {
     parent::process();
     try {
         $this->profile = Teleport::loadProfile($this->profile);
         $this->getMODX($this->profile);
         $this->modx->setOption(\xPDO::OPT_SETUP, true);
         $this->modx->loadClass('transport.xPDOTransport', XPDO_CORE_PATH, true, true);
         $this->modx->loadClass('transport.xPDOVehicle', XPDO_CORE_PATH, true, true);
         $this->modx->loadClass('transport.xPDOObjectVehicle', XPDO_CORE_PATH, true, true);
         $this->modx->loadClass('transport.xPDOFileVehicle', XPDO_CORE_PATH, true, true);
         $transportName = basename($this->source);
         if (TELEPORT_BASE_PATH . 'workspace' . DIRECTORY_SEPARATOR . $transportName !== realpath($this->source)) {
             if (!$this->pull($this->source, TELEPORT_BASE_PATH . 'workspace' . DIRECTORY_SEPARATOR . $transportName)) {
                 throw new ActionException($this, "Error pulling {$this->source}");
             }
         } else {
             $this->preserveWorkspace = true;
         }
         $this->package = Transport::retrieve($this->modx, TELEPORT_BASE_PATH . 'workspace' . DIRECTORY_SEPARATOR . $transportName, TELEPORT_BASE_PATH . 'workspace' . DIRECTORY_SEPARATOR);
         if (!$this->package instanceof Transport) {
             throw new ActionException($this, "Error extracting {$transportName} in workspace" . DIRECTORY_SEPARATOR);
         }
         $this->package->preInstall();
         if (!$this->package->install(array(\xPDOTransport::PREEXISTING_MODE => \xPDOTransport::REMOVE_PREEXISTING))) {
             throw new ActionException($this, "Error installing {$transportName}");
         }
         $this->package->postInstall();
         if ($this->modx->getCacheManager()) {
             $this->modx->cacheManager->refresh();
         }
         if (!$this->preserveWorkspace && $this->modx->getCacheManager()) {
             $this->modx->cacheManager->deleteTree($this->package->path . $transportName);
             @unlink($this->package->path . $transportName . '.transport.zip');
         }
         $this->request->log("Successfully injected {$transportName} into instance {$this->profile->code}");
     } catch (\Exception $e) {
         throw new ActionException($this, 'Error injecting snapshot: ' . $e->getMessage(), $e);
     }
 }
Example #7
0
 public function handle(array $arguments)
 {
     $this->parseArguments($arguments);
     $start = microtime(true);
     $loop = \React\EventLoop\Factory::create();
     $process = new \React\ChildProcess\Process($this->getCLICommand());
     $message = '';
     $request =& $this;
     $teleport = \Teleport\Teleport::instance();
     $process->on('exit', function ($exitCode, $termSignal) use($teleport, $request, $start, &$message) {
         $request->results = explode(PHP_EOL, rtrim($message, PHP_EOL));
         if ($request->args('debug') || $request->args('verbose')) {
             array_push($request->results, sprintf("request finished with exit code {$exitCode} in %2.4f seconds" . PHP_EOL, microtime(true) - $start));
         }
         if ($teleport->getConfig()->get('verbose', null, false) || $teleport->getConfig()->get('debug', null, false)) {
             echo sprintf("process finished with exit code {$exitCode} in %2.4f seconds" . PHP_EOL, microtime(true) - $start);
         }
     });
     $loop->addTimer(0.001, function ($timer) use($teleport, $request, $process, &$message) {
         if ($teleport->getConfig()->get('verbose', null, false) || $teleport->getConfig()->get('debug', null, false)) {
             echo "process started using cmd: {$process->getCommand()}" . PHP_EOL;
         }
         $process->start($timer->getLoop());
         $process->stdout->on('data', function ($output) use($teleport, $request, &$message) {
             $message .= $output;
             if ($teleport->getConfig()->get('verbose', null, false) || $teleport->getConfig()->get('debug', null, false)) {
                 echo $output;
             }
         });
         $process->stderr->on('data', function ($output) use($teleport, $request, &$message) {
             $message .= $output;
             if ($teleport->getConfig()->get('verbose', null, false) || $teleport->getConfig()->get('debug', null, false)) {
                 echo $output;
             }
         });
     });
     $loop->run();
 }
Example #8
0
        // Increase memory_limit if it is lower than 512M
        if ($memoryInBytes($memoryLimit) < 512 * 1024 * 1024) {
            @ini_set('memory_limit', '512M');
        }
        unset($memoryInBytes);
    }
    unset($memoryLimit);
}
try {
    require_once __DIR__ . '/../src/bootstrap.php';
    define('TELEPORT_BASE_PATH', rtrim(getcwd(), '/') . '/');
    $options = array('debug' => $debug);
    if (is_readable('config.php')) {
        $options = (include 'config.php');
    }
    $teleport = \Teleport\Teleport::instance($options);
    $request = $teleport->getRequest();
    array_shift($argv);
    $request->handle($argv);
    $results = implode(PHP_EOL, $request->getResults());
    echo trim($results) . PHP_EOL;
    if ($debug) {
        printf("execution finished with exit code 0 in %2.4f seconds" . PHP_EOL, microtime(true) - $start);
    }
    exit(0);
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL;
    if ($debug) {
        printf("execution failed with exit code {$e->getCode()} in %2.4f seconds" . PHP_EOL, microtime(true) - $start);
    }
    exit($e->getCode());