Skip to content

Commit d9e0f52

Browse files
committed
Added queue which holds a list of groups to sync.
1 parent 21357e8 commit d9e0f52

File tree

8 files changed

+186
-34
lines changed

8 files changed

+186
-34
lines changed

app/AppKernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function registerBundles()
2222
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
2323
new Hslavich\SimplesamlphpBundle\HslavichSimplesamlphpBundle(),
2424
new SmartCore\Bundle\AcceleratorCacheBundle\AcceleratorCacheBundle(),
25+
new Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle(),
2526
// custom bundles
2627
new AppBundle\AppBundle(),
2728
];

app/config/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,8 @@ hslavich_simplesamlphp:
9292
accelerator_cache:
9393
host: %url%
9494
web_dir: %kernel.root_dir%/../web
95+
96+
doctrine_cache:
97+
providers:
98+
cache:
99+
type: file_system

app/config/services.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ services:
2525
arguments: ["@guzzle.client.api_grouphub", "@app.api_normalizer"]
2626
private: true
2727

28+
app.queue:
29+
class: AppBundle\Service\QueueService
30+
arguments: ["@doctrine_cache.providers.cache"]
31+
private: true
32+
2833
app.sync:
2934
class: AppBundle\Service\SyncService
30-
arguments: ["@app.grouphub_ldap_client", "@app.api_client", "@logger", "%admin_groups_sync%"]
35+
arguments: ["@app.grouphub_ldap_client", "@app.api_client", "@logger", "@app.queue", "%admin_groups_sync%"]
3136

3237
twig.extension.intl:
3338
class: Twig_Extensions_Extension_Intl
@@ -36,7 +41,7 @@ services:
3641

3742
app.group_manager:
3843
class: AppBundle\Manager\GroupManager
39-
arguments: ["@app.api_client", "@app.grouphub_ldap_client"]
44+
arguments: ["@app.api_client", "@app.queue"]
4045

4146
app.membership_manager:
4247
class: AppBundle\Manager\MembershipManager

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"require": {
2020
"php": ">=5.5.9",
2121
"symfony/symfony": "3.0.*",
22-
"doctrine/doctrine-cache-bundle": "^1.2",
22+
"doctrine/doctrine-cache-bundle": "^1.3",
2323
"symfony/swiftmailer-bundle": "^2.3",
2424
"symfony/monolog-bundle": "^2.8",
2525
"sensio/distribution-bundle": "^5.0",

composer.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AppBundle/Manager/GroupManager.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace AppBundle\Manager;
44

55
use AppBundle\Api\ApiClient;
6-
use AppBundle\Ldap\GrouphubClient;
76
use AppBundle\Model\Collection;
87
use AppBundle\Model\Group;
8+
use AppBundle\Service\QueueService;
99

1010
/**
1111
* Class GroupManager
@@ -18,18 +18,18 @@ class GroupManager
1818
private $client;
1919

2020
/**
21-
* @var GrouphubClient
21+
* @var QueueService
2222
*/
23-
private $ldapClient;
23+
private $queue;
2424

2525
/***
26-
* @param ApiClient $client
27-
* @param GrouphubClient $ldapClient
26+
* @param ApiClient $client
27+
* @param QueueService $queue
2828
*/
29-
public function __construct(ApiClient $client, GrouphubClient $ldapClient)
29+
public function __construct(ApiClient $client, QueueService $queue)
3030
{
3131
$this->client = $client;
32-
$this->ldapClient = $ldapClient;
32+
$this->queue = $queue;
3333
}
3434

3535
/**
@@ -156,14 +156,18 @@ public function getGroup($id)
156156
public function deleteGroup($id)
157157
{
158158
$this->client->removeGroup($id);
159+
160+
$this->queue->addGroupToQueue($id);
159161
}
160162

161163
/**
162164
* @param Group $group
163165
*/
164166
public function addGroup(Group $group)
165167
{
166-
$this->client->addGroup($group);
168+
$group = $this->client->addGroup($group);
169+
170+
$this->queue->addGroupToQueue($group->getId());
167171
}
168172

169173
/**
@@ -172,5 +176,7 @@ public function addGroup(Group $group)
172176
public function updateGroup(Group $group)
173177
{
174178
$this->client->updateGroup($group->getId(), $group);
179+
180+
$this->queue->addGroupToQueue($group->getId());
175181
}
176182
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace AppBundle\Service;
4+
5+
use Doctrine\Common\Cache\Cache;
6+
7+
/**
8+
* Class QueueService
9+
*/
10+
class QueueService
11+
{
12+
const QUEUE_CACHE_ID = 'grouphub-groups-queue';
13+
14+
/**
15+
* @var Cache
16+
*/
17+
private $cache;
18+
19+
/**
20+
* @param Cache $cache
21+
*/
22+
public function __construct(Cache $cache)
23+
{
24+
$this->cache = $cache;
25+
}
26+
27+
/**
28+
* @return int[]
29+
*/
30+
public function getQueuedGroups()
31+
{
32+
if (!$this->cache->contains(self::QUEUE_CACHE_ID)) {
33+
return [];
34+
}
35+
36+
$groupIds = $this->cache->fetch(self::QUEUE_CACHE_ID);
37+
38+
if (!is_array($groupIds)) {
39+
return [];
40+
}
41+
42+
return $groupIds;
43+
}
44+
45+
/**
46+
*
47+
*/
48+
public function clearGroupQueue()
49+
{
50+
$this->cache->delete(self::QUEUE_CACHE_ID);
51+
}
52+
53+
/**
54+
* @param int $id
55+
*/
56+
public function addGroupToQueue($id)
57+
{
58+
$groupIds = [];
59+
60+
if ($this->cache->contains(self::QUEUE_CACHE_ID)) {
61+
$groupIds = $this->cache->fetch(self::QUEUE_CACHE_ID);
62+
}
63+
64+
$groupIds[$id] = $id;
65+
66+
$this->cache->save(self::QUEUE_CACHE_ID, $groupIds);
67+
}
68+
}

0 commit comments

Comments
 (0)