diff --git a/cron/status.cron.php b/cron/status.cron.php
index 01882636..0905d8da 100644
--- a/cron/status.cron.php
+++ b/cron/status.cron.php
@@ -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);
diff --git a/src/config/services.xml b/src/config/services.xml
index 98b4577a..3fb66aae 100644
--- a/src/config/services.xml
+++ b/src/config/services.xml
@@ -32,6 +32,9 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/sc
%db.pass%
+
+
+
@@ -47,6 +50,9 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/sc
+
+
+
\ No newline at end of file
diff --git a/src/psm/Module/Server/Controller/UpdateController.class.php b/src/psm/Module/Server/Controller/UpdateController.class.php
index 94a3f64a..e0b5b230 100644
--- a/src/psm/Module/Server/Controller/UpdateController.class.php
+++ b/src/psm/Module/Server/Controller/UpdateController.class.php
@@ -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(
diff --git a/src/psm/Util/Server/UpdateManager.class.php b/src/psm/Util/Server/UpdateManager.class.php
index 7695b3a6..13ea2d04 100644
--- a/src/psm/Util/Server/UpdateManager.class.php
+++ b/src/psm/Util/Server/UpdateManager.class.php
@@ -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;
- }
}
\ No newline at end of file