1
|
|
|
<?php |
2
|
|
|
namespace keeko\core\installer; |
3
|
|
|
|
4
|
|
|
use Composer\IO\IOInterface; |
5
|
|
|
use keeko\core\model\Package; |
6
|
|
|
use keeko\core\model\PackageQuery; |
7
|
|
|
use keeko\core\service\ServiceContainer; |
8
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
9
|
|
|
use keeko\core\schema\KeekoPackageSchema; |
10
|
|
|
use keeko\core\model\ExtensionQuery; |
11
|
|
|
use keeko\core\model\Extension; |
12
|
|
|
use phootwork\json\Json; |
13
|
|
|
|
14
|
|
|
abstract class AbstractPackageInstaller { |
15
|
|
|
|
16
|
|
|
/** @var ServiceContainer */ |
17
|
|
|
protected $service; |
18
|
|
|
|
19
|
|
|
/** @var EventDispatcher */ |
20
|
|
|
protected $dispatcher; |
21
|
|
|
|
22
|
|
|
public function __construct(ServiceContainer $service) { |
23
|
|
|
$this->service = $service; |
|
|
|
|
24
|
|
|
$this->dispatcher = $this->service->getDispatcher(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Installs a package |
29
|
|
|
* |
30
|
|
|
* @param IOInterface $io the IOInterface |
31
|
|
|
* @param string $packageName |
32
|
|
|
* @throws MissingOptionsException when required parameters for the package are missing |
33
|
|
|
*/ |
34
|
|
|
abstract public function install(IOInterface $io, $packageName); |
|
|
|
|
35
|
|
|
|
36
|
|
|
abstract public function update(IOInterface $io, $packageName, $from, $to); |
|
|
|
|
37
|
|
|
|
38
|
|
|
abstract public function uninstall(IOInterface $io, $packageName); |
|
|
|
|
39
|
|
|
|
40
|
|
|
protected function updatePackage(Package &$model, KeekoPackageSchema $pkg) { |
41
|
|
|
$packageName = $pkg->getPackage()->getFullName(); |
42
|
|
|
$result = PackageQuery::create()->filterByName($packageName)->count(); |
|
|
|
|
43
|
|
|
$info = $this->service->getPackageManager()->getComposerPackage($packageName); |
|
|
|
|
44
|
|
|
|
45
|
|
|
if ($result == 0) { |
46
|
|
|
$model->setTitle($pkg->getTitle()); |
47
|
|
|
$model->setDescription($info->getDescription()); |
48
|
|
|
$model->setName($packageName); |
49
|
|
|
$model->setInstalledVersion($info->getPrettyVersion()); |
50
|
|
|
$model->save(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$this->updateExtensions($model, $pkg); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
protected function getPackageSchema($packageName) { |
57
|
|
|
return $this->service->getPackageManager()->getPackage($packageName); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function updateExtensions(Package &$model, KeekoPackageSchema $pkg) { |
61
|
|
|
// remove all existing extensions from this package first |
62
|
|
|
ExtensionQuery::create()->filterByPackage($model)->deleteAll(); |
63
|
|
|
|
64
|
|
|
// add them one by one |
65
|
|
|
foreach ($pkg->getExtensions() as $key => $data) { |
66
|
|
|
$ext = new Extension(); |
67
|
|
|
$ext->setKey($key); |
68
|
|
|
$ext->setData(Json::encode($data)); |
69
|
|
|
$ext->save(); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.