NagiosDynamicSettings.php in Nagios Monitoring 8
File
src/Plugin/migrate/source/NagiosDynamicSettings.php
View source
<?php
namespace Drupal\nagios\Plugin\migrate\source;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
class NagiosDynamicSettings extends DrupalSqlBase {
public function query() {
$var_names = array_map(function (string $module_name) {
return 'nagios_enable_' . $module_name;
}, array_keys(\Drupal::moduleHandler()
->getModuleList()));
return $this
->select('variable', 'v')
->fields('v', [
'name',
'value',
])
->condition('name', $var_names, 'IN')
->condition('value', 's:0:"";', '<>');
}
public function getIds() {
$ids['name']['type'] = 'string';
return $ids;
}
public function fields() {
return [
'name' => "The name of the variable.",
'value' => "The value of the variable.",
];
}
public function prepareRow(Row $row) {
$var_name = $row
->getSourceProperty('name');
$module_name = str_replace('nagios_enable_', '', $var_name);
$value = unserialize($row
->getSourceProperty('value'), [
'allowed_classes' => FALSE,
]);
$row
->setDestinationProperty('nagios/enable/' . $module_name, $value);
}
}