function htaccess_cron in Htaccess 8.2
Same name and namespace in other branches
- 7.2 htaccess.module \htaccess_cron()
File
- ./
htaccess.module, line 24 - Htaccess is a module which autogenerates a Drupal root htaccess file based on your settings.
Code
function htaccess_cron() {
// try to get current htaccess content
$root_path = \Drupal::root();
$htaccess_filepath = $root_path . '/.htaccess';
$htaccess_current = file_get_contents($htaccess_filepath);
if ($htaccess_current) {
// Get the current htaccess deployed
$htaccess_deployed = db_select('htaccess', 'h')
->fields('h')
->condition('deployed', 1, '=')
->execute()
->fetchAssoc();
if ($htaccess_deployed) {
$htaccess_deployed = $htaccess_deployed['htaccess'];
// Compare the two results
if ($htaccess_current === $htaccess_deployed) {
\Drupal::config('htaccess.settings')
->clear('htaccess_altered')
->save();
}
else {
drupal_set_message(t('The htaccess seems to be altered.'), 'warning');
\Drupal::configFactory()
->getEditable('htaccess.settings')
->set('htaccess_altered', true)
->save();
}
}
}
}