Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
backup_migrate
Manage
Activity
Members
Labels
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
backup_migrate
Commits
22766c15
There was an error fetching the commit references. Please try again later.
Commit
22766c15
authored
9 years ago
by
Ronan Dowling
Browse files
Options
Downloads
Patches
Plain Diff
Refactor to new services di
parent
45a28370
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
backup_migrate.module
+72
-18
72 additions, 18 deletions
backup_migrate.module
with
72 additions
and
18 deletions
backup_migrate.module
+
72
−
18
View file @
22766c15
...
...
@@ -12,8 +12,9 @@ require __DIR__.'/vendor/autoload.php';
*/
function
backup_migrate_perform_backup
(
$source_id
,
$destination_id
,
$config
=
[])
{
try
{
//
Creat
e the service
//
Retriev
e the service
$bam
=
backup_migrate_get_service_object
(
$config
);
// Run the backup.
$bam
->
backup
(
$source_id
,
$destination_id
);
}
...
...
@@ -34,57 +35,110 @@ function backup_migrate_get_service_object($config_array = []) {
// If the static cached object has not been loaded.
if
(
$bam
===
NULL
)
{
// Create the config object.
$conf
=
new
\BackupMigrate\Core\Config\Config
(
$config_array
);
// Create the environment services.
$logger
=
new
\BackupMigrate\Drupal\Environment\DrupalSetMessageLogger
();
$files
=
new
\BackupMigrate\Drupal\File\DrupalTempFileAdapter
(
\Drupal
::
service
(
'file_system'
),
'temporary://'
,
'bam'
);
// @TODO: Implement Drupal specific caching and state storage.
$cache
=
NULL
;
$state
=
NULL
;
$mailer
=
NULL
;
// Create the service locator
$services
=
new
\BackupMigrate\Core\Service\ServiceLocator
();
// Allow other modules to add services.
\Drupal
::
moduleHandler
()
->
alter
(
'backup_migrate_services'
,
$services
);
// Create the plugin manager
$plugins
=
new
\BackupMigrate\Core\Plugin\PluginManager
(
$services
);
//
Bundle the servic
es
in
to a
n environment object
$env
=
new
\B
ackup
M
igrate
\Drupal\Environment\DrupalEnvironment
(
$files
,
$cache
,
$state
,
$logger
,
$mailer
);
//
Allow other modul
es to a
dd plugins.
\Drupal
::
moduleHandler
()
->
alter
(
'b
ackup
_m
igrate
_plugins'
,
$plugins
);
// Create the service object.
$bam
=
new
\BackupMigrate\Core\
Service
\BackupMigrate
(
$
env
,
$conf
);
$bam
=
new
\BackupMigrate\Core\
Main
\BackupMigrate
(
$
plugins
);
// Allow other modules to alter the object
\Drupal
::
moduleHandler
()
->
alter
(
'backup_migrate_service_object'
,
$bam
);
}
else
if
(
$config_array
)
{
// Set the configuration overrides if any were passed in.
if
(
$config_array
)
{
$bam
->
setConfig
(
new
\BackupMigrate\Core\Config\Config
(
$config_array
));
}
return
$bam
;
}
/**
* Implements hook_backup_migrate_services_alter().
*
* Add the core Backup and Migrate services to the service locator.
*
* @param \BackupMigrate\Core\Service\ServiceLocatorInterface $services
*/
function
backup_migrate_backup_migrate_services_alter
(
\BackupMigrate\Core\Service\ServiceLocator
&
$services
)
{
// Add a temp file manager which can access the drupal temp directory.
$services
->
add
(
'TempFileAdapter'
,
new
\BackupMigrate\Drupal\File\DrupalTempFileAdapter
(
\Drupal
::
service
(
'file_system'
),
'temporary://'
,
'bam'
)
);
$services
->
add
(
'TempFileManager'
,
new
\BackupMigrate\Core\File\TempFileManager
(
$services
->
get
(
'TempFileAdapter'
))
);
// Add a logger which prints everything to the browser.
$services
->
add
(
'Logger'
,
new
\BackupMigrate\Drupal\Environment\DrupalSetMessageLogger
()
);
}
/**
* Implements hook_backup_migrate_service_object_alter().
*
* Add the core Backup and Migrate plugins to the service object.
*
* @param \BackupMigrate\Core\
Service\BackupMigrate $bam
* @param \BackupMigrate\Core\
Plugin\PluginManagerInterface $plugins
*/
function
backup_migrate_backup_migrate_service_object_alter
(
\BackupMigrate\Core\Service\BackupMigrate
&
$bam
)
{
function
backup_migrate_backup_migrate_plugins_alter
(
\BackupMigrate\Core\Plugin\PluginManagerInterface
&
$plugins
)
{
// Add the default database.
$info
=
\Drupal\Core\Database\Database
::
getConnectionInfo
(
'default'
,
'default'
);
$info
=
$info
[
'default'
];
if
(
$info
[
'driver'
]
==
'mysql'
)
{
$
bam
->
plugins
()
->
add
(
$plugins
->
add
(
new
\BackupMigrate\Core\Source\MySQLiSource
(
new
\BackupMigrate\Core\Config\Config
(
$info
)
),
'db'
);
}
// Add a download destination.
$
bam
->
plugins
()
->
add
(
new
\BackupMigrate\Drupal\Destination\DrupalBrowserDownloadDestination
(),
'download'
);
$plugins
->
add
(
new
\BackupMigrate\Drupal\Destination\DrupalBrowserDownloadDestination
(),
'download'
);
// Add a file naming filter.
$bam
->
plugins
()
->
add
(
new
\BackupMigrate\Core\Filter\FileNamer
(),
'namer'
);
$plugins
->
add
(
new
\BackupMigrate\Core\Filter\FileNamer
(),
'namer'
);
// Add an S3 destination.
// $bam->plugins()->add(
// new \BackupMigrate\Drupal\Destination\DrupalS3Destination(
// new \BackupMigrate\Core\Config\Config(
// ['prefix' => 'path/to/backups'],
// ),
// new \BackupMigrate\Drupal\Destination\S3ReaderWriter([
// 'credentials' => s3_get_credentials(),
// ]),
// new \BackupMigrate\Drupal\Destination\S3Writer(),
//
// ), 'download');
//
// // Add an File destination.
// $bam->plugins()->add(
// new \BackupMigrate\Drupal\Destination\FileDirectorySource(
// new \BackupMigrate\Drupal\Services\TarArchiveReader(),
// new \BackupMigrate\Drupal\Services\TarArchiveWriter(),
// new \BackupMigrate\Core\Config\Config(
// ['directory' => 'public://']
//
// )
// ), 'files_public');
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment