Same filename in this branch
- 8.x-2.x advagg_bundler/src/EventSubscriber/InitSubscriber.php
Same filename and directory in other branches
- 5.0.x advagg_mod/src/EventSubscriber/InitSubscriber.php
- 6.0.x advagg_mod/src/EventSubscriber/InitSubscriber.php
- 8.x-3.x advagg_mod/src/EventSubscriber/InitSubscriber.php
- 8.x-4.x advagg_mod/src/EventSubscriber/InitSubscriber.php
Namespace
Drupal\advagg_mod\EventSubscriber
Fichier
-
advagg_mod/src/EventSubscriber/InitSubscriber.php
View source
<?php
namespace Drupal\advagg_mod\EventSubscriber;
use Drupal\Core\Config\ConfigFactoryInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class InitSubscriber implements EventSubscriberInterface {
protected $config;
protected $advaggConfig;
public function __construct(ConfigFactoryInterface $config_factory) {
$this->config = $config_factory->get('advagg.settings');
$this->advaggConfig = $config_factory->getEditable('advagg.settings');
}
public static function getSubscribedEvents() {
return [
KernelEvents::REQUEST => [
'onEvent',
0,
],
];
}
public function onEvent() {
$dir = rtrim($this->config
->get('unified_multisite_dir'), '/');
if (empty($dir) || !file_exists($dir) || !is_dir($dir)) {
return;
}
$counter_filename = $dir . '/_global_counter';
$local_counter = advagg_get_global_counter();
if (!file_exists($counter_filename)) {
file_unmanaged_save_data($local_counter, $counter_filename, FILE_EXISTS_REPLACE);
}
else {
$shared_counter = (int) file_get_contents($counter_filename);
if ($shared_counter == $local_counter) {
return;
}
elseif ($shared_counter < $local_counter) {
ile_unmanaged_save_data($local_counter, $counter_filename, FILE_EXISTS_REPLACE);
return;
}
elseif ($shared_counter > $local_counter) {
$this->advaggConfig
->set('global_counter', $shared_counter)
->save();
return;
}
}
}
}
Classes
| Titre |
Deprecated |
Résumé |
| InitSubscriber |
|
Perform initialization tasks for advagg_mod. |