You are here

class DrupalSiteArchiveSource in Backup and Migrate 8.4

Class DrupalSiteArchiveSource.

@package BackupMigrate\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/Source/DrupalSiteArchiveSource.php, line 20

Namespace

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

  /**
   * @var SourceInterface
   */
  protected $db_source;

  /**
   * @param ConfigInterface|array $init
   * @param \BackupMigrate\Core\Source\SourceInterface $db
   * @param \BackupMigrate\Core\Source\SourceInterface $code
   */
  public function __construct($init = [], SourceInterface $db) {
    parent::__construct($init);
    $this->db_source = $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 \BackupMigrate\Core\Exception\BackupMigrateException
   * @throws \BackupMigrate\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 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 \BackupMigrate\Core\File\BackupFileWritableInterface
   */
  protected function getManifestFile() {
    $out = $this
      ->getTempFileManager()
      ->create('ini');
    $info = [
      'Global' => [
        'datestamp' => time(),
        "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($info) {
    $content = "";
    foreach ($info as $section => $data) {
      $content .= '[' . $section . ']' . "\n";
      foreach ($data as $key => $val) {
        $content .= $key . " = \"" . $val . "\"\n";
      }
      $content .= "\n";
    }
    return $content;
  }

  /**
   * @return SourceInterface
   */
  public function getDbSource() {
    return $this->db_source;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigurableTrait::$config protected property The object's configuration object.
ConfigurableTrait::$init protected property The initial configuration. These configuration options can be overriden by the config options but will not be overwritten. If the object is re-configured after construction any missing configuration options will revert to these values.
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::$db_source 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. Do not include files that match the 'exclude_filepaths' setting. 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. This is the main restore function for this source. Overrides FileDirectorySource::importFromFile
DrupalSiteArchiveSource::__construct public function Overrides ConfigurableTrait::__construct
FileDirectorySource::$archive_reader private property
FileDirectorySource::$archive_writer 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. This should be the main back up function for this source. Overrides SourceInterface::exportToFile
FileDirectorySource::getArchiveReader public function
FileDirectorySource::getArchiveWriter public function
FileDirectorySource::setArchiveReader public function
FileDirectorySource::setArchiveWriter public function
FileDirectorySource::supportedOps public function Get a list of supported operations and their weight. Overrides PluginBase::supportedOps
FileDirectorySource::_getFilesFromDirectory protected function @internal param string $dir
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.