本文整理汇总了PHP中Path::get_instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Path::get_instance方法的具体用法?PHP Path::get_instance怎么用?PHP Path::get_instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Path
的用法示例。
在下文中一共展示了Path::get_instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
$this->backup = new Backup('backup.zip');
$this->setup_test_data();
Path::get_instance()->set_path($this->test_data . '/tmp');
Path::get_instance()->set_root($this->test_data);
}
示例2: setUp
public function setUp()
{
$this->setup_test_data();
Path::get_instance()->set_path($this->test_data . '/tmp');
Path::get_instance()->set_root($this->test_data);
$this->backup = new Mock_File_Backup_Engine();
}
示例3: setUp
public function setUp()
{
$this->setup_test_data();
Path::get_instance()->set_path($this->test_data . '/tmp');
Path::get_instance()->set_root($this->test_data);
$this->status = new Backup_Status('status1');
}
示例4: setUp
public function setUp()
{
$this->size = new Site_Size();
$this->setup_test_data();
Path::get_instance()->set_path($this->test_data . '/tmp');
Path::get_instance()->set_root($this->test_data);
$this->root = new \SplFileInfo(Path::get_root());
}
示例5: setUp
public function setUp()
{
// We need to mess with the $is_apache global so let's back it up now
global $is_apache;
$this->is_apache = $is_apache;
$this->path = Path::get_instance();
$this->custom_path = wp_normalize_path(WP_CONTENT_DIR . '/custom');
// Cleanup before we kickoff in-case theirs cruft around from previous failures
$this->tearDown();
}
示例6: test_only_database_zipped_up
public function test_only_database_zipped_up()
{
$this->backup->set_type('database');
Path::get_instance()->reset_path();
file_put_contents(PATH::get_path() . '/foo.zip.SmuhtP', 'bar');
file_put_contents(PATH::get_path() . '/zicBotXQ', 'baz');
$this->backup->run();
$this->assertFileExists($this->backup->get_backup_filepath());
$this->assertArchiveContains($this->backup->get_backup_filepath(), array(basename($this->backup->get_database_backup_filepath())));
$this->assertArchiveNotContains($this->backup->get_backup_filepath(), array('zicBotXQ', 'foo.zip.SmuhtP'));
$this->assertArchiveFileCount($this->backup->get_backup_filepath(), 1);
}
示例7: backup
/**
* Perform a Backup.
*
* ## OPTIONS
*
* [--files_only]
* : Backup files only, default to off
*
* [--database_only]
* : Backup database only, defaults to off
*
* [--destination]
* : dir that the backup should be save in, defaults to your existing backups directory
*
* [--root]
* : dir that should be backed up, defaults to site root.
*
* [--zip_command_path]
* : path to your zip binary, standard locations are automatically used
*
* [--mysqldump_command_path]
* : path to your mysqldump binary, standard locations are automatically used
*
* [--archive_filename]
* : filename for the resulting zip file
*
* [--excludes]
* : list of paths you'd like to exclude
*
* ## Usage
*
* wp backupwordpress backup [--files_only] [--database_only] [--path<dir>] [--root<dir>] [--zip_command_path=<path>] [--mysqldump_command_path=<path>]
*
* @todo errors should be bubbled from Backup, Scheduled_Backup and the like instead of being repeated.
*/
public function backup($args, $assoc_args)
{
add_action('hmbkp_mysqldump_started', function () {
WP_CLI::line(__('Backup: Dumping database...', 'backupwordpress'));
});
add_action('hmbkp_archive_started', function () {
WP_CLI::line(__('Backup: Zipping everything up...', 'backupwordpress'));
});
$hm_backup = new HM\BackUpWordPress\Backup();
if (!empty($assoc_args['destination'])) {
Path::get_instance()->set_path($assoc_args['destination']);
}
HM\BackUpWordPress\Path::get_instance()->cleanup();
if (!empty($assoc_args['root'])) {
$hm_backup->set_root($assoc_args['root']);
}
if (!is_dir(hmbkp_path())) {
WP_CLI::error(__('Invalid backup path', 'backupwordpress'));
return false;
}
if (!is_dir($hm_backup->get_root()) || !is_readable($hm_backup->get_root())) {
WP_CLI::error(__('Invalid root path', 'backupwordpress'));
return false;
}
if (isset($assoc_args['archive_filename'])) {
$hm_backup->set_archive_filename($assoc_args['archive_filename']);
}
if (!empty($assoc_args['files_only'])) {
$hm_backup->set_type('file');
}
if (!empty($assoc_args['database_only'])) {
$hm_backup->set_type('database');
}
if (isset($assoc_args['mysqldump_command_path'])) {
$hm_backup->set_mysqldump_command_path($assoc_args['mysqldump_command_path']);
}
if (isset($assoc_args['zip_command_path'])) {
$hm_backup->set_zip_command_path($assoc_args['zip_command_path']);
}
if (!empty($assoc_args['excludes'])) {
$hm_backup->set_excludes($assoc_args['excludes']);
}
$hm_backup->backup();
if (file_exists($hm_backup->get_archive_filepath())) {
WP_CLI::success(__('Backup Complete: ', 'backupwordpress') . $hm_backup->get_archive_filepath());
} else {
WP_CLI::error(__('Backup Failed', 'backupwordpress'));
}
}
示例8: backup_database
public function backup_database()
{
if ($this->status) {
$this->status->set_status(__('Backing up database...', 'backupwordpress'));
}
$database_backup_engines = apply_filters('hmbkp_database_backup_engines', array(new Mysqldump_Database_Backup_Engine(), new IMysqldump_Database_Backup_Engine()));
// Set the file backup engine settings
if ($this->database_dump_filename) {
foreach ($database_backup_engines as &$backup_engine) {
$backup_engine->set_backup_filename($this->database_dump_filename);
}
}
// Dump the database
$database_dump = $this->perform_backup($database_backup_engines);
if (is_a($database_dump, __NAMESPACE__ . '\\Backup_Engine')) {
$this->database_dump_filepath = $database_dump->get_backup_filepath();
}
// Fire up the file backup engines
$file_backup_engines = apply_filters('hmbkp_file_backup_engines', array(new Zip_File_Backup_Engine(), new Zip_Archive_File_Backup_Engine()));
// Set the file backup engine settings
foreach ($file_backup_engines as &$backup_engine) {
$backup_engine->set_backup_filename($this->backup_filename);
$backup_engine->set_excludes(new Excludes(array('*.zip', 'index.html', '.htaccess', '.*-running')));
}
// Zip up the database dump
$root = Path::get_root();
Path::get_instance()->set_root(Path::get_path());
$file_backup = $this->perform_backup($file_backup_engines);
Path::get_instance()->set_root($root);
if (is_a($file_backup, __NAMESPACE__ . '\\Backup_Engine')) {
$this->backup_filepath = $file_backup->get_backup_filepath();
}
// Delete the Database Backup now that we've zipped it up
if (file_exists($this->database_dump_filepath)) {
unlink($this->database_dump_filepath);
}
}
示例9: init
/**
* Runs on every admin page load
*/
public function init()
{
// If we have multiple paths for some reason then clean them up
Path::get_instance()->merge_existing_paths();
}
示例10: test_complete_file_backup
/**
* Test a complete backup of the WordPress Site
*
* @group full-backup
*/
public function test_complete_file_backup()
{
// Reset root back to defaults
Path::get_instance()->set_root(false);
$this->backup->backup();
$finder = $this->backup->get_files();
foreach ($finder as $file) {
$files[] = $file->getRelativePathname();
}
$this->assertFileExists($this->backup->get_backup_filepath());
$this->assertArchiveFileCount($this->backup->get_backup_filepath(), iterator_count($finder));
$this->assertArchiveContains($this->backup->get_backup_filepath(), $files);
}
示例11: dismiss_error
/**
* Dismiss an error and then redirect back to the backups page
*/
function dismiss_error()
{
Path::get_instance()->cleanup();
Notices::get_instance()->clear_all_notices();
wp_safe_redirect(wp_get_referer(), 303);
die;
}
示例12: update
/**
* Handles anything that needs to be
* done when the plugin is updated
*/
function update()
{
// Update from backUpWordPress 0.4.5
if (get_option('bkpwp_max_backups')) {
// Carry over the custom path
if ($legacy_path = get_option('bkpwppath')) {
update_option('hmbkp_path', $legacy_path);
}
// Options to remove
$legacy_options = array('bkpwp_archive_types', 'bkpwp_automail_from', 'bkpwp_domain', 'bkpwp_domain_path', 'bkpwp_easy_mode', 'bkpwp_excludelists', 'bkpwp_install_user', 'bkpwp_listmax_backups', 'bkpwp_max_backups', 'bkpwp_presets', 'bkpwp_reccurrences', 'bkpwp_schedules', 'bkpwp_calculation', 'bkpwppath', 'bkpwp_status_config', 'bkpwp_status');
foreach ($legacy_options as $option) {
delete_option($option);
}
global $wp_roles;
$wp_roles->remove_cap('administrator', 'manage_backups');
$wp_roles->remove_cap('administrator', 'download_backups');
wp_clear_scheduled_hook('bkpwp_schedule_bkpwp_hook');
}
// Version 1 to 2
if (get_option('hmbkp_plugin_version') && version_compare('2.0', get_option('hmbkp_plugin_version'), '>')) {
/**
* Setup a backwards compatible schedule
*/
$legacy_schedule = new Scheduled_Backup('backup');
// Backup type
if (defined('HMBKP_FILES_ONLY') && HMBKP_FILES_ONLY || get_option('hmbkp_files_only')) {
$legacy_schedule->set_type('file');
} elseif (defined('HMBKP_DATABASE_ONLY') && HMBKP_DATABASE_ONLY || get_option('hmbkp_database_only')) {
$legacy_schedule->set_type('database');
} else {
$legacy_schedule->set_type('complete');
}
// Daily schedule time
if (defined('HMBKP_DAILY_SCHEDULE_TIME') && HMBKP_DAILY_SCHEDULE_TIME) {
$legacy_schedule->set_schedule_start_time(strtotime(HMBKP_DAILY_SCHEDULE_TIME));
}
// Backup schedule
$legacy_schedule->set_reoccurrence(get_option('hmbkp_schedule_frequency', 'daily'));
// Automatic backups disabled?
if (defined('HMBKP_DISABLE_AUTOMATIC_BACKUP') && HMBKP_DISABLE_AUTOMATIC_BACKUP || get_option('hmbkp_disable_automatic_backup')) {
$legacy_schedule->set_reoccurrence('manually');
}
// Max backups
if (defined('HMBKP_MAX_BACKUPS') && is_numeric(HMBKP_MAX_BACKUPS)) {
$legacy_schedule->set_max_backups((int) HMBKP_MAX_BACKUPS);
} else {
$legacy_schedule->set_max_backups((int) get_option('hmbkp_max_backups', 10));
}
// Excludes
if (get_option('hmbkp_excludes')) {
$legacy_schedule->set_excludes(get_option('hmbkp_excludes'));
}
// Backup email
if (defined('HMBKP_EMAIL') && is_email(HMBKP_EMAIL)) {
$legacy_schedule->set_service_options('HMBKP_Email_Service', array('email' => HMBKP_EMAIL));
} elseif (is_email(get_option('hmbkp_email_address'))) {
$legacy_schedule->set_service_options('HMBKP_Email_Service', array('email' => get_option('hmbkp_email_address')));
}
// Set the archive filename to what it used to be
$legacy_schedule->backup_filename = implode('-', array(get_bloginfo('name'), 'backup', current_time('Y-m-d-H-i-s'))) . '.zip';
$legacy_schedule->save();
$legacy_path = get_option('hmbkp_path');
if ($legacy_path) {
// Prepend 'backup-' to the beginning of any legacy backups so they are picked up by the legacy schedule
if ($handle = opendir($legacy_path)) {
while (false !== ($file = readdir($handle))) {
if ('zip' === pathinfo($file, PATHINFO_EXTENSION)) {
rename(trailingslashit($legacy_path) . $file, trailingslashit($legacy_path) . 'backup-' . $file);
}
}
closedir($handle);
}
PATH::get_instance()->move_old_backups($legacy_path);
}
// Remove the legacy options
foreach (array('hmbkp_database_only', 'hmbkp_files_only', 'hmbkp_max_backups', 'hmbkp_email_address', 'hmbkp_email', 'hmbkp_schedule_frequency', 'hmbkp_disable_automatic_backup') as $option_name) {
delete_option($option_name);
}
}
// Update from 2.x to 3.0
if (get_option('hmbkp_plugin_version') && version_compare('2.0', get_option('hmbkp_plugin_version'), '>')) {
// Remove the plugin data cache
delete_transient('hmbkp_plugin_data');
}
// Update to 3.1
if (get_option('hmbkp_plugin_version') && version_compare('3.0', get_option('hmbkp_plugin_version'), '>')) {
// Remove the plugin data cache
delete_option('hmbkp_path');
delete_option('hmbkp_default_path');
}
// update to 3.1.4
if (get_option('hmbkp_plugin_version') && version_compare('3.1.4', get_option('hmbkp_plugin_version'), '>')) {
$old_option_names = array('HM\\BackUpWordPressDropbox\\Dropbox_Service' => 'dropbox', 'HMBKP_DX_Backup_Service' => 'dropbox', 'HM\\BackUpWordPressFTP\\FTP_Backup_Service' => 'ftp', 'HMBKP_FTP_Backup_Service' => 'ftp', 'HM\\BackUpWordPressGDrive\\Google_Drive_BackUp' => 'google-drive', 'HMBKP_GDV_Backup_Service' => 'google-drive', 'HM\\BackUpWordPressRackspace\\RackSpace_BackUp' => 'rackspace-cloud', 'HMBKP_RSC_Backup_Service' => 'rackspace-cloud', 'HM\\BackUpWordPressS3\\S3_Backup' => 's3', 'HMBKP_S3_Backup_Service' => 's3', 'HM\\BackUpWordPressWinAzure\\WinAzure_Backup' => 'azure', 'HMBKP_WAZ_Backup_Service' => 'azure', 'HM\\BackUpWordPress\\Email_Service' => 'email');
global $wpdb;
// Get all schedule options with a SELECT query and delete them.
$schedules = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s", 'hmbkp_schedule_%'));
//.........这里部分代码省略.........
示例13: test_cleanup
public function test_cleanup()
{
// Should be cleaned up
file_put_contents(PATH::get_path() . '/foo.zip.SmuhtP', 'bar');
file_put_contents(PATH::get_path() . '/foo.sql', 'bar');
file_put_contents(PATH::get_path() . '/zicBotXQ', 'baz');
// Existing backups shouldn't be cleaned up
file_put_contents(PATH::get_path() . '/backup.zip', 'baz');
Path::get_instance()->cleanup();
$this->assertFileNotExists(PATH::get_path() . '/foo.zip.SmuhtP');
$this->assertFileNotExists(PATH::get_path() . '/foo.sql');
$this->assertFileNotExists(PATH::get_path() . '/zicBotXQ');
$this->assertFileExists(PATH::get_path() . '/index.html');
$this->assertFileExists(PATH::get_path() . '/backup.zip');
}
示例14: setUp
public function setUp()
{
$this->setup_test_data();
Path::get_instance()->set_path($this->test_data . '/tmp');
Path::get_instance()->set_root($this->test_data);
}
示例15: test
/**
* @return string
*/
protected function test()
{
return Path::get_instance()->get_path();
}