You are here

class AcsfDuplicationScrubInitializeHandler in Acquia Cloud Site Factory Connector 8.2

Same name and namespace in other branches
  1. 8 src/Event/AcsfDuplicationScrubInitializeHandler.php \Drupal\acsf\Event\AcsfDuplicationScrubInitializeHandler

Handles initialization operations for the scrub.

Hierarchy

Expanded class hierarchy of AcsfDuplicationScrubInitializeHandler

File

src/Event/AcsfDuplicationScrubInitializeHandler.php, line 11

Namespace

Drupal\acsf\Event
View source
class AcsfDuplicationScrubInitializeHandler extends AcsfEventHandler {

  /**
   * Implements AcsfEventHandler::handle().
   */
  public function handle() {
    $this
      ->consoleLog(dt('Entered @class', [
      '@class' => get_class($this),
    ]));
    if (!$this
      ->isComplete()) {
      $site = AcsfSite::load();
      $site
        ->clean();
      \Drupal::config('system.site')
        ->set('name', $this->event->context['site_name'])
        ->save();
      $state_storage = \Drupal::state();
      $state_storage
        ->delete('acsf_duplication_scrub_status');
      $state_storage
        ->set('install_time', time());

      // As a preparatory step, remove any corrupt file entries that may prevent
      // duplication from succeeding. Specifically, remove any file with an
      // empty URI string.
      $fids = \Drupal::entityQuery('file')
        ->condition('uri', '')
        ->execute();
      $files = File::loadMultiple($fids);
      foreach ($files as $file) {
        try {
          $file
            ->delete();
        } catch (\Exception $e) {

          // OK, we'll live with not scrubbing this.
        }
      }
      $this
        ->setComplete();
    }
  }

  /**
   * Returns if this step has already completed.
   */
  public function isComplete() {
    return \Drupal::service('acsf.variable_storage')
      ->get('acsf_site_duplication_step_initialize_complete', FALSE);
  }

  /**
   * Sets a flag to indicate that this step has completed.
   */
  protected function setComplete() {
    \Drupal::service('acsf.variable_storage')
      ->set('acsf_site_duplication_step_initialize_complete', TRUE, 'acsf_duplication_scrub');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AcsfDuplicationScrubInitializeHandler::handle public function Implements AcsfEventHandler::handle(). Overrides AcsfEventHandler::handle
AcsfDuplicationScrubInitializeHandler::isComplete public function Returns if this step has already completed.
AcsfDuplicationScrubInitializeHandler::setComplete protected function Sets a flag to indicate that this step has completed.
AcsfEventHandler::$completed public property The time that the handler was completed.
AcsfEventHandler::$message public property Any messages triggered by the handler.
AcsfEventHandler::$started public property The time that the handler was started.
AcsfEventHandler::consoleLog public function Writes a log message to the console.
AcsfEventHandler::__construct public function Constructor. 1