PluginProbe
ManageWP Worker / trunk
ManageWP Worker vtrunk
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / MWP / Action / IncrementalBackup / AbstractTablesAction.php

AbstractTablesAction.php in ManageWP Worker trunk, at src/MWP/Action/IncrementalBackup/AbstractTablesAction.php

98 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * This file is part of the ManageWP Worker plugin.
4 *
5 * (c) ManageWP LLC <[email protected]>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 abstract class MWP_Action_IncrementalBackup_AbstractTablesAction extends MWP_Action_IncrementalBackup_Abstract
12 {
13 const METHOD_MYSQLDUMP = 'mysqldump';
14 const METHOD_PHPDUMPER = 'phpdumper';
15
16 /**
17 * @param MWP_IncrementalBackup_Database_DumperInterface $dumper
18 * @param array $params
19 * @param array $tables
20 *
21 * @return mixed
22 */
23 abstract protected function executeAction(MWP_IncrementalBackup_Database_DumperInterface $dumper, array $tables = array(), array $params = array());
24
25 public function execute(array $params = array())
26 {
27 $method = $params['method'];
28 $tables = $params['tables'];
29
30 if (isset($params['options']) && is_array($params['options'])) {
31 $options = $params['options'];
32 } else {
33 $options = array();
34 }
35
36 $dumper = $this->createDumper($method, $options);
37
38 return $this->executeAction($dumper, $tables, $params);
39 }
40
41 /**
42 * @param array $tables
43 *
44 * @throws MWP_Worker_Exception
45 */
46 protected function assertTablesExist(array $tables)
47 {
48 $rows = mwp_context()->getDb()->get_results("SHOW TABLES", ARRAY_N);
49 foreach ($rows as $row) {
50 // $row is always an array with only a single member
51 $table = $row[0];
52
53 $index = array_search($table, $tables);
54 if ($index !== false) {
55 // Remove from $tables - don't worry, $tables has not been passed by reference :)
56 array_splice($tables, $index, 1);
57 }
58 }
59
60 // Tables which have not been found are located in $tables
61 if (count($tables)) {
62 throw new MWP_Worker_Exception(MWP_Worker_Exception::BACKUP_DATABASE_MISSING_TABLES, "Some tables are missing", array(
63 // Return an array of missing tables
64 'tables' => $tables,
65 ));
66 }
67 }
68
69 /**
70 * @param string $method
71 *
72 * @param array $options
73 *
74 * @throws MWP_Worker_Exception
75 * @return MWP_IncrementalBackup_Database_DumperInterface
76 */
77 protected function createDumper($method, array $options = array())
78 {
79 $dumperOptions = MWP_IncrementalBackup_Database_DumpOptions::createFromArray($options);
80
81 switch ($method) {
82 case self::METHOD_MYSQLDUMP:
83 $configuration = MWP_IncrementalBackup_Database_Configuration::createFromWordPressContext(mwp_context());
84 $dumper = new MWP_IncrementalBackup_Database_MysqlDumpDumper($configuration, $dumperOptions);
85
86 return $dumper;
87 case self::METHOD_PHPDUMPER:
88 $configuration = MWP_IncrementalBackup_Database_Configuration::createFromWordPressContext(mwp_context());
89 $dumper = new MWP_IncrementalBackup_Database_PhpDumper($configuration, mwp_container()->getSystemEnvironment(), $dumperOptions);
90
91 return $dumper;
92 default:
93 throw new MWP_Worker_Exception(MWP_Worker_Exception::BACKUP_DATABASE_METHOD_NOT_AVAILABLE);
94 break;
95 }
96 }
97 }
98