| 1 | <?php |
||
| 5 | class BuildAddonJob extends AbstractQueuedJob |
||
| 6 | { |
||
| 7 | private $packageID; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * @var array params |
||
| 11 | * @throws Exception |
||
| 12 | */ |
||
| 13 | public function __construct($params = array()) |
||
| 14 | { |
||
| 15 | if (!empty($params['package'])) { |
||
| 16 | $this->PackageID = $params['package']; |
||
| 17 | } |
||
| 18 | |||
| 19 | $this->currentStep = 0; |
||
| 20 | $this->totalSteps = 1; |
||
| 21 | } |
||
| 22 | |||
| 23 | protected function getPackage() |
||
| 24 | { |
||
| 25 | return Addon::get()->byID($this->PackageID); |
||
| 26 | } |
||
| 27 | |||
| 28 | public function process(context) |
||
|
|
|||
| 29 | { |
||
| 30 | $package = $this->getPackage(); |
||
| 31 | if (!$package->ID) { |
||
| 32 | throw new Exception('Package not specified'); |
||
| 33 | } |
||
| 34 | |||
| 35 | $builder = Injector::inst()->get('AddonBuilder'); |
||
| 36 | |||
| 37 | $builder->build($package); |
||
| 38 | |||
| 39 | $package->BuildQueued = false; |
||
| 40 | $package->write(); |
||
| 41 | |||
| 42 | $this->isComplete = true; |
||
| 43 | $this->currentStep = 1; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @return string |
||
| 48 | */ |
||
| 49 | public function getTitle() |
||
| 50 | { |
||
| 51 | return 'Build Addon: ' . $this->getPackge()->Name; |
||
| 52 | } |
||
| 53 | /** |
||
| 54 | * Return a signature for this queued job |
||
| 55 | * |
||
| 56 | * @return string |
||
| 57 | */ |
||
| 58 | public function getSignature() |
||
| 59 | { |
||
| 60 | return md5(get_class($this) . $this->PackageID); |
||
| 61 | } |
||
| 62 | |||
| 63 | } |
||
| 64 |