You are here

function htaccess_deploy_profile in Htaccess 7.2

Same name and namespace in other branches
  1. 8.2 htaccess.drush.inc \htaccess_deploy_profile()
1 call to htaccess_deploy_profile()
htaccess_htaccess_deploy in ./htaccess.drush.inc
Callback function for drush htaccess.

File

./htaccess.drush.inc, line 68

Code

function htaccess_deploy_profile($profile_name) {
  $root_path = DRUPAL_ROOT;
  $htaccess_path = $root_path . '/.htaccess';
  $htaccess_get = db_select('htaccess', 'h')
    ->fields('h')
    ->condition('name', array(
    ':profile_name' => $profile_name,
  ), 'IN')
    ->execute()
    ->fetchAssoc();
  $htaccess_content = $htaccess_get['htaccess'];
  if (file_put_contents($htaccess_path, $htaccess_content)) {

    // Get the current htaccess deployed
    $htaccess_current = db_select('htaccess', 'h')
      ->fields('h')
      ->condition('deployed', 1, '=')
      ->execute()
      ->fetchAssoc();

    // If any, set the status to 0
    if ($htaccess_current) {
      db_update('htaccess')
        ->fields(array(
        'deployed' => 0,
      ))
        ->condition('id', $htaccess_current['id'], '=')
        ->execute();
    }

    // Set the status to 1
    db_update('htaccess')
      ->fields(array(
      'deployed' => 1,
    ))
      ->condition('id', $htaccess_get['id'], '=')
      ->execute();
    drupal_chmod($htaccess_path, 0644);
    return true;
  }
  else {
    return false;
  }
}