You are here

class DrupalSiteArchiveSource in Backup and Migrate 5.0.x

@package Drupal\backup_migrate\Drupal\Source

Hierarchy

Expanded class hierarchy of DrupalSiteArchiveSource

1 file declares its use of DrupalSiteArchiveSource
EntireSiteSourcePlugin.php in src/Plugin/BackupMigrateSource/EntireSiteSourcePlugin.php

File

src/Drupal/Source/DrupalSiteArchiveSource.php, line 14

Namespace

Drupal\backup_migrate\Drupal\Source
View source
class DrupalSiteArchiveSource extends FileDirectorySource {

  /**
   * @var \Drupal\backup_migrate\Core\Source\SourceInterface
   */
  protected $dbSource;

  /**
   * @param \Drupal\backup_migrate\Core\Config\ConfigInterface|array $init
   * @param \Drupal\backup_migrate\Core\Source\SourceInterface $db
   */
  public function __construct($init, SourceInterface $db) {
    parent::__construct($init);
    $this->dbSource = $db;
  }

  /**
   * Get a list if files to be backed up from the given directory.
   *
   * Do not include files that match the 'exclude_filepaths' setting.
   *
   * @param string $dir
   *   The name of the directory to list.
   *
   * @return array
   *
   * @throws \Drupal\backup_migrate\Core\Exception\BackupMigrateException
   * @throws \Drupal\backup_migrate\Core\Exception\IgnorableException
   *
   * @internal param $directory
   */
  protected function getFilesToBackup($dir) {
    $files = [];

    // Add the database dump.
    // @todo realpath contains the wrong filename and the PEAR archiver cannot rename files.
    $db = $this
      ->getDbSource()
      ->exportToFile();
    $files['database.sql'] = $db
      ->realpath();

    // Add the manifest file.
    $manifest = $this
      ->getManifestFile();
    $files['MANIFEST.ini'] = $manifest
      ->realpath();

    // Get all the files in the site.
    foreach (parent::getFilesToBackup($dir) as $new => $real) {

      // Prepend 'docroot' onto the local path.
      $files['docroot/' . $new] = $real;
    }
    return $files;
  }

  /**
   * Import to this source from the given backup file.
   *
   * This is the main restore function for this source.
   *
   * @param \Drupal\backup_migrate\Core\File\BackupFileReadableInterface $file
   *   The file to read the backup from. It will not be opened for reading.
   *
   * @return bool|void
   */
  public function importFromFile(BackupFileReadableInterface $file) {

    // @todo Implement importFromFile() method.
  }

  /**
   * Get a file which contains the file.
   *
   * @return \Drupal\backup_migrate\Core\File\BackupFileWritableInterface
   */
  protected function getManifestFile() {
    $out = $this
      ->getTempFileManager()
      ->create('ini');
    $info = [
      'Global' => [
        'datestamp' => \Drupal::time()
          ->getRequestTime(),
        "formatversion" => "2011-07-02",
        "generator" => "Backup and Migrate (http://drupal.org/project/backup_migrate)",
        "generatorversion" => backup_migrate_module_version(),
      ],
      'Site 0' => [
        'version' => \Drupal::VERSION,
        'name' => "Example.com",
        'docroot' => "docroot",
        'sitedir' => "docroot/sites/default",
        'database-file-default' => "database.sql",
        'database-file-driver' => "mysql",
        'files-private' => "docroot/sites/default/private",
        'files-public' => "docroot/sites/default/files",
      ],
    ];
    $out
      ->writeAll($this
      ->arrayToIni($info));
    return $out;
  }

  /**
   * Translate a 2d array to an INI string which can be written to a file.
   *
   * @param array $info
   *   The array to convert. Must be an array of sections each of which is an
   *   array of field/value pairs.
   *
   * @return string
   *   The data in INI format.
   */
  private function arrayToIni(array $info) {
    $content = "";
    foreach ($info as $section => $data) {
      $content .= '[' . $section . ']' . "\n";
      foreach ($data as $key => $val) {
        $content .= $key . " = \"" . $val . "\"\n";
      }
      $content .= "\n";
    }
    return $content;
  }

  /**
   * @return \Drupal\backup_migrate\Core\Source\SourceInterface
   */
  public function getDbSource() {
    return $this->dbSource;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigurableTrait::$config protected property The object's configuration object.
ConfigurableTrait::$init protected property The initial configuration.
ConfigurableTrait::confGet public function Get a specific value from the configuration.
ConfigurableTrait::config public function Get the configuration object for this item.
ConfigurableTrait::configErrors public function Get any validation errors in the config.
ConfigurableTrait::setConfig public function Set the configuration for all plugins. 1
DrupalSiteArchiveSource::$dbSource protected property
DrupalSiteArchiveSource::arrayToIni private function Translate a 2d array to an INI string which can be written to a file.
DrupalSiteArchiveSource::getDbSource public function
DrupalSiteArchiveSource::getFilesToBackup protected function Get a list if files to be backed up from the given directory. Overrides FileDirectorySource::getFilesToBackup
DrupalSiteArchiveSource::getManifestFile protected function Get a file which contains the file.
DrupalSiteArchiveSource::importFromFile public function Import to this source from the given backup file. Overrides FileDirectorySource::importFromFile
DrupalSiteArchiveSource::__construct public function Overrides ConfigurableTrait::__construct
FileDirectorySource::$archiveReader private property
FileDirectorySource::$archiveWriter private property
FileDirectorySource::configDefaults public function Get the default values for the plugin. Overrides ConfigurableTrait::configDefaults 1
FileDirectorySource::configSchema public function Get a definition for user-configurable settings. Overrides ConfigurableTrait::configSchema
FileDirectorySource::exportToFile public function Export this source to the given temp file. Overrides SourceInterface::exportToFile
FileDirectorySource::getArchiveReader public function
FileDirectorySource::getArchiveWriter public function
FileDirectorySource::getFilesFromDirectory protected function @internal param string $dir
FileDirectorySource::setArchiveReader public function
FileDirectorySource::setArchiveWriter public function
FileDirectorySource::supportedOps public function Get a list of supported operations and their weight. Overrides PluginBase::supportedOps
FileProcessorTrait::$tempfilemanager protected property
FileProcessorTrait::alterMime public function Provide the file mime for the given file extension if known.
FileProcessorTrait::getTempFileManager public function Get the temp file manager.
FileProcessorTrait::setTempFileManager public function Inject the temp file manager.
PluginBase::opWeight public function What is the weight of the given operation for this plugin. Overrides PluginInterface::opWeight
PluginBase::supportsOp public function Does this plugin implement the given operation. Overrides PluginInterface::supportsOp
PluginCallerTrait::$plugins protected property
PluginCallerTrait::plugins public function Get the plugin manager.
PluginCallerTrait::setPluginManager public function Inject the plugin manager.
TranslatableTrait::$translator protected property
TranslatableTrait::setTranslator public function
TranslatableTrait::t public function Translate the given string if there is a translator service available.