Skip to content

Commit c493b1e

Browse files
Auto-update through the admin panel
1 parent 0528c45 commit c493b1e

File tree

3 files changed

+134
-3
lines changed

3 files changed

+134
-3
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
}
2828
},
2929
"extra": {
30+
"class": "skeeks\\cms\\marketplace\\composer\\UpdatePlugin",
3031
"config-plugin": {
3132
"web": "src/config/web.php"
3233
}

src/composer/UpdatePlugin.php

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php
2+
/**
3+
* Composer plugin for config assembling
4+
*
5+
* @link https://github.com/hiqdev/composer-config-plugin
6+
* @package composer-config-plugin
7+
* @license BSD-3-Clause
8+
* @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9+
*/
10+
11+
namespace skeeks\cms\marketplace\composer;
12+
13+
use Composer\Composer;
14+
use Composer\EventDispatcher\EventSubscriberInterface;
15+
use Composer\IO\IOInterface;
16+
use Composer\Package\CompletePackageInterface;
17+
use Composer\Package\PackageInterface;
18+
use Composer\Package\RootPackageInterface;
19+
use Composer\Plugin\PluginInterface;
20+
use Composer\Script\Event;
21+
use Composer\Script\ScriptEvents;
22+
use Composer\Util\Filesystem;
23+
24+
/**
25+
* Class UpdatePlugin
26+
* @package skeeks\cms\marketplace\composer
27+
*/
28+
class UpdatePlugin implements PluginInterface, EventSubscriberInterface
29+
{
30+
/**
31+
* @var string absolute path to the package base directory
32+
*/
33+
protected $baseDir;
34+
/**
35+
* @var string absolute path to vendor directory
36+
*/
37+
protected $vendorDir;
38+
/**
39+
* @var Filesystem utility
40+
*/
41+
protected $filesystem;
42+
43+
/**
44+
* @var Composer instance
45+
*/
46+
protected $composer;
47+
/**
48+
* @var IOInterface
49+
*/
50+
public $io;
51+
52+
/**
53+
* Initializes the plugin object with the passed $composer and $io.
54+
* @param Composer $composer
55+
* @param IOInterface $io
56+
*/
57+
public function activate(Composer $composer, IOInterface $io)
58+
{
59+
$this->composer = $composer;
60+
$this->io = $io;
61+
}
62+
63+
/**
64+
* Returns list of events the plugin is subscribed to.
65+
* @return array list of events
66+
*/
67+
public static function getSubscribedEvents()
68+
{
69+
return [
70+
ScriptEvents::POST_AUTOLOAD_DUMP => [
71+
['onPostAutoloadDump', 0],
72+
],
73+
];
74+
}
75+
76+
/**
77+
* This is the main function.
78+
* @param Event $event
79+
*/
80+
public function onPostAutoloadDump(Event $event)
81+
{
82+
$this->io->writeError('<info>After all update</info>');
83+
$this->initAutoload();
84+
}
85+
86+
protected function initAutoload()
87+
{
88+
$dir = dirname(dirname(dirname(__DIR__)));
89+
require_once "$dir/autoload.php";
90+
}
91+
92+
93+
/**
94+
* Get absolute path to package base dir.
95+
* @return string
96+
*/
97+
public function getBaseDir()
98+
{
99+
if (null === $this->baseDir) {
100+
$this->baseDir = dirname($this->getVendorDir());
101+
}
102+
return $this->baseDir;
103+
}
104+
105+
/**
106+
* Get absolute path to composer vendor dir.
107+
* @return string
108+
*/
109+
public function getVendorDir()
110+
{
111+
if (null === $this->vendorDir) {
112+
$dir = $this->composer->getConfig()->get('vendor-dir');
113+
$this->vendorDir = $this->getFilesystem()->normalizePath($dir);
114+
}
115+
return $this->vendorDir;
116+
}
117+
118+
/**
119+
* Getter for filesystem utility.
120+
* @return Filesystem
121+
*/
122+
public function getFilesystem()
123+
{
124+
if (null === $this->filesystem) {
125+
$this->filesystem = new Filesystem();
126+
}
127+
return $this->filesystem;
128+
}
129+
}

src/views/admin-composer-update/update.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<? endif; ?>
3434
</div>
3535
<hr/>
36-
<div class="row sx-update-wrapper">
37-
<div class="col-md-12 text-center">
36+
<div class="row">
37+
<div class="col-md-12 text-center sx-update-wrapper">
3838
<div class=" btn btn-primary btn-lg sx-btn-run">
3939
<?= \Yii::t('skeeks/marketplace', 'Start update'); ?>
4040
</div>
@@ -131,7 +131,8 @@
131131
132132
Handler.bind('error', function() {
133133
self.trigger('errorStep');
134-
self.trigger('stopUpdate');
134+
/*self.trigger('stopUpdate');*/
135+
self.runStep();
135136
});
136137
137138
AjaxQuery.execute();

0 commit comments

Comments
 (0)