Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/worker/src/MWP/Action/Incremen...
File: GetViewSchema.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
* This file is part of the ManageWP Worker plugin.
[2] Fix | Delete
*
[3] Fix | Delete
* (c) ManageWP LLC <contact@managewp.com>
[4] Fix | Delete
*
[5] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[6] Fix | Delete
* file that was distributed with this source code.
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
class MWP_Action_IncrementalBackup_GetViewSchema
[10] Fix | Delete
{
[11] Fix | Delete
const ERROR_VIEW_NOT_FOUND = 1;
[12] Fix | Delete
[13] Fix | Delete
public function execute(array $params = array())
[14] Fix | Delete
{
[15] Fix | Delete
$views = $params['views'];
[16] Fix | Delete
[17] Fix | Delete
$result = array();
[18] Fix | Delete
[19] Fix | Delete
foreach ($views as $view) {
[20] Fix | Delete
if (!$this->viewExists($view)) {
[21] Fix | Delete
$result[] = array(
[22] Fix | Delete
'name' => $view,
[23] Fix | Delete
'error' => self::ERROR_VIEW_NOT_FOUND,
[24] Fix | Delete
);
[25] Fix | Delete
continue;
[26] Fix | Delete
}
[27] Fix | Delete
[28] Fix | Delete
$createTableSql = $this->getCreateViewSql($view);
[29] Fix | Delete
[30] Fix | Delete
$result[] = array(
[31] Fix | Delete
'name' => $view,
[32] Fix | Delete
'createViewSql' => $createTableSql,
[33] Fix | Delete
);
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
return $result;
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
private function viewExists($table)
[40] Fix | Delete
{
[41] Fix | Delete
$exists = (int) mwp_context()->getDb()->get_var(
[42] Fix | Delete
sprintf('SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = "%s" AND table_name = "%s"',
[43] Fix | Delete
mwp_context()->escapeParameter(mwp_context()->getDbName()),
[44] Fix | Delete
mwp_context()->escapeParameter($table))
[45] Fix | Delete
);
[46] Fix | Delete
[47] Fix | Delete
return $exists >= 1;
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
private function getCreateViewSql($table)
[51] Fix | Delete
{
[52] Fix | Delete
$createTableResults = mwp_context()->getDb()->get_results(
[53] Fix | Delete
sprintf('SHOW CREATE VIEW `%s`', $this->escapeTableName($table)),
[54] Fix | Delete
ARRAY_A
[55] Fix | Delete
);
[56] Fix | Delete
[57] Fix | Delete
return isset($createTableResults[0]['Create View']) ? $createTableResults[0]['Create View'] : null;
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
/**
[61] Fix | Delete
* Escape backticks (`) in table names.
[62] Fix | Delete
* A table can contain a backtick character (`) and it has to be escaped with another backtick.
[63] Fix | Delete
* This is only relevant
[64] Fix | Delete
*
[65] Fix | Delete
* e.g. asd`asd should be converted into asd``asd.
[66] Fix | Delete
* The resulting SQL query should look like: SELECT * FROM `asd``asd`;
[67] Fix | Delete
*
[68] Fix | Delete
* @param string $table
[69] Fix | Delete
*
[70] Fix | Delete
* @return string
[71] Fix | Delete
*/
[72] Fix | Delete
private function escapeTableName($table)
[73] Fix | Delete
{
[74] Fix | Delete
return str_replace('`', '``', $table);
[75] Fix | Delete
}
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function