function css_injector_update_7203 in CSS Injector 7.2
Import the 1.x rules to the new 2.x structure
File
- ./
css_injector.install, line 243 - css_injector.install
Code
function css_injector_update_7203(&$sandbox) {
module_load_include('inc', 'ctools', 'includes/export');
$results = db_query("SELECT * FROM {css_injector_rule}", array(), array(
'fetch' => PDO::FETCH_ASSOC,
))
->fetchAllAssoc('crid');
foreach ($results as $id => $rule) {
$path = _css_injector_rule_uri($rule['crid']);
if (file_exists($path)) {
$css = file_get_contents($path);
}
else {
$css = NULL;
drupal_set_message(t('CSS Injector was unable to import CSS from file for @var
during the update. The structure of the rule was updated, but the CSS field will be empty.
Because the expected .css file does not exist and the CSS was only stored in that file,
there is no way to recover this data. The 2.x version of CSS Injector now stores the
CSS in the database in addition to writing it to a file.', array(
'@var' => $rule['name'],
)), 'warning');
}
$names = array(
$rule['name'],
);
$newrule = ctools_export_load_object('css_injector_rule', 'names', $names);
$newrule[$rule['name']]->css = $css;
css_injector_rule_save($newrule[$rule['name']]);
}
}