/
Inject.php
92 lines (77 loc) · 3.29 KB
/
Inject.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* This file is part of the teleport package.
*
* Copyright (c) MODX, LLC
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Teleport\Action;
use Teleport\Teleport;
use Teleport\Transport\Transport;
/**
* Inject a Snapshot into a MODX Instance.
*
* @property \stdClass profile
* @property string source
* @property bool preserveWorkspace
*
* @package Teleport\Action
*/
class Inject extends Action
{
/**
* @var array The required arguments for this action.
*/
protected $required = array('profile', 'source');
/**
* @var Transport The Transport package to be Injected into the \modX instance.
*/
public $package;
/**
* 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);
}
}
}