class ModifierIndex in Persistent URL 8
Hierarchy
- class \Drupal\purl\Plugin\ModifierIndex
Expanded class hierarchy of ModifierIndex
4 files declare their use of ModifierIndex
- ModifiersController.php in src/
Controller/ ModifiersController.php - ProvidersController.php in src/
Controller/ ProvidersController.php - RebuildIndex.php in src/
Event/ RebuildIndex.php - RequestSubscriber.php in src/
Event/ RequestSubscriber.php
1 string reference to 'ModifierIndex'
1 service uses ModifierIndex
File
- src/
Plugin/ ModifierIndex.php, line 8
Namespace
Drupal\purl\PluginView source
class ModifierIndex {
protected $connection;
protected $providerManager;
public function __construct(ProviderManager $providerManager, Connection $connection) {
$this->providerManager = $providerManager;
$this->connection = $connection;
}
public function findModifiers() {
$result = $this->connection
->select('purl_modifiers', 'p')
->fields('p', array(
'provider',
'modifier',
'value',
))
->execute();
return array_map(function ($row) {
return array_merge((array) $row, array(
'value' => unserialize($row->value),
));
}, $result
->fetchAll());
}
public function indexModifiers(ProviderInterface $provider, $method) {
$id = $provider
->getId();
$modifiers = $provider
->getModifiers();
if (!is_array($modifiers)) {
return;
}
$this
->deleteEntriesByProvider($provider
->getId());
foreach ($modifiers as $modifier => $value) {
$this->connection
->insert('purl_modifiers')
->fields(array(
'modifier' => $modifier,
'provider' => $id,
'value' => serialize($value),
))
->execute();
}
$this->connection
->update('purl_providers_settings')
->condition('provider', $provider
->getId())
->fields(array(
'rebuild' => 0,
))
->execute();
}
public function deleteEntriesByProvider($providerId) {
$this->connection
->delete('purl_modifiers')
->condition('provider', $providerId)
->execute();
}
public function deleteAll() {
$this->connection
->delete('purl_modifiers')
->execute();
}
public function rebuild($providerId = null, $immediately = false) {
if ($immediately) {
if (!$providerId) {
throw new \BadMethodCallException('A provider must be specified during immediate rebuilds.');
}
$provider = $this->providerManager
->getProvider($providerId);
$definition = $this->providerManager
->getDefinition($providerId);
if (!$definition['method']) {
return;
}
$this
->indexModifiers($providerId, $definition['method']);
}
else {
$statement = $this->connection
->update('purl_providers_settings')
->fields(array(
'rebuild' => 1,
));
if ($providerId) {
$statement
->condition('provider', $providerId);
}
$statement
->execute();
}
}
public function performDueRebuilds() {
$result = $this->connection
->select('purl_providers_settings', 'p')
->fields('p', array(
'provider',
'method',
))
->condition('p.rebuild', 1)
->execute();
foreach ($result
->fetchAll() as $row) {
$provider = $this->providerManager
->getProvider($row->provider);
$this
->indexModifiers($provider, $row->method);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ModifierIndex:: |
protected | property | ||
ModifierIndex:: |
protected | property | ||
ModifierIndex:: |
public | function | ||
ModifierIndex:: |
public | function | ||
ModifierIndex:: |
public | function | ||
ModifierIndex:: |
public | function | ||
ModifierIndex:: |
public | function | ||
ModifierIndex:: |
public | function | ||
ModifierIndex:: |
public | function |