[refactoring] moving UpdateManger to service container as util.server.updatemanager
parent
f63a39d92c
commit
dc54bf14ea
|
@ -68,7 +68,7 @@ if(!defined('PSM_DEBUG') || !PSM_DEBUG) {
|
|||
}
|
||||
psm_update_conf('cron_running_time', $time);
|
||||
|
||||
$autorun = new \psm\Util\Server\UpdateManager($db);
|
||||
$autorun->run();
|
||||
$autorun = $router->getService('util.server.updatemanager');
|
||||
$autorun->run(true);
|
||||
|
||||
psm_update_conf('cron_running', 0);
|
||||
|
|
|
@ -32,6 +32,9 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/sc
|
|||
<argument>%db.pass%</argument>
|
||||
</service>
|
||||
|
||||
<service id="event" class="Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher">
|
||||
<argument type="service" id="service_container" />
|
||||
</service>
|
||||
<service id="user" class="psm\Service\User">
|
||||
<argument type="service" id="db" />
|
||||
</service>
|
||||
|
@ -47,6 +50,9 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/sc
|
|||
<service id="util.user.validator" class="psm\Util\User\UserValidator">
|
||||
<argument type="service" id="user" />
|
||||
</service>
|
||||
<service id="util.server.updatemanager" class="psm\Util\Server\UpdateManager">
|
||||
<argument type="service" id="service_container" />
|
||||
</service>
|
||||
<!--UTIL end-->
|
||||
</services>
|
||||
</container>
|
|
@ -40,8 +40,7 @@ class UpdateController extends AbstractController {
|
|||
}
|
||||
|
||||
protected function executeIndex() {
|
||||
$autorun = new \psm\Util\Server\UpdateManager($this->db);
|
||||
$autorun->setUser($this->getUser());
|
||||
$autorun = $this->container->get('util.server.updatemanager');
|
||||
$autorun->run();
|
||||
|
||||
header('Location: ' . psm_build_url(array(
|
||||
|
|
|
@ -27,44 +27,31 @@
|
|||
**/
|
||||
|
||||
namespace psm\Util\Server;
|
||||
use psm\Service\Database;
|
||||
use psm\Service\User;
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Run an update on all servers.
|
||||
*
|
||||
* If you provide a User service instance it will be
|
||||
* restricted to that user only.
|
||||
*/
|
||||
class UpdateManager {
|
||||
class UpdateManager extends ContainerAware {
|
||||
|
||||
/**
|
||||
* Database service
|
||||
* @var \psm\Service\Database $db
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* User service
|
||||
* @var \psm\Service\User $user
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
function __construct(Database $db) {
|
||||
$this->db = $db;
|
||||
function __construct(ContainerInterface $container) {
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Go :-)
|
||||
*
|
||||
* @param boolean $skip_perms if TRUE, no user permissions will be taken in account and all servers will be updated
|
||||
*/
|
||||
public function run() {
|
||||
public function run($skip_perms = false) {
|
||||
// check if we need to restrict the servers to a certain user
|
||||
$sql_join = '';
|
||||
|
||||
if($this->user != null && $this->user->getUserLevel() > PSM_USER_ADMIN) {
|
||||
if(!$skip_perms && $this->container->get('user')->getUserLevel() > PSM_USER_ADMIN) {
|
||||
// restrict by user_id
|
||||
$sql_join = "JOIN `".PSM_DB_PREFIX."users_servers` AS `us` ON (
|
||||
`us`.`user_id`={$this->user->getUserId()}
|
||||
`us`.`user_id`={$this->container->get('user')->getUserId()}
|
||||
AND `us`.`server_id`=`s`.`server_id`
|
||||
)";
|
||||
}
|
||||
|
@ -74,10 +61,10 @@ class UpdateManager {
|
|||
{$sql_join}
|
||||
WHERE `active`='yes' ";
|
||||
|
||||
$servers = $this->db->query($sql);
|
||||
$servers = $this->container->get('db')->query($sql);
|
||||
|
||||
$updater = new Updater\StatusUpdater($this->db);
|
||||
$notifier = new Updater\StatusNotifier($this->db);
|
||||
$updater = new Updater\StatusUpdater($this->container->get('db'));
|
||||
$notifier = new Updater\StatusNotifier($this->container->get('db'));
|
||||
|
||||
foreach($servers as $server) {
|
||||
$status_old = ($server['status'] == 'on') ? true : false;
|
||||
|
@ -87,16 +74,8 @@ class UpdateManager {
|
|||
}
|
||||
|
||||
// clean-up time!! archive all records
|
||||
$archive = new ArchiveManager($this->db);
|
||||
$archive = new ArchiveManager($this->container->get('db'));
|
||||
$archive->archive();
|
||||
$archive->cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a user to restrict the servers being updated
|
||||
* @param \psm\Service\User $user
|
||||
*/
|
||||
public function setUser(User $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue