forked from LiveCarta/LiveCartaWP
Changed source root directory
This commit is contained in:
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Utils\Log\Log;
|
||||
|
||||
abstract class DUPX_Validation_abstract_item
|
||||
{
|
||||
const LV_FAIL = 0;
|
||||
const LV_HARD_WARNING = 1;
|
||||
const LV_SOFT_WARNING = 2;
|
||||
const LV_GOOD = 3;
|
||||
const LV_PASS = 4;
|
||||
const LV_SKIP = 1000;
|
||||
|
||||
protected $category = '';
|
||||
protected $testResult = null;
|
||||
|
||||
public function __construct($category = '')
|
||||
{
|
||||
$this->category = $category;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param bool $reset
|
||||
*
|
||||
* @return int // test result level
|
||||
*/
|
||||
public function test($reset = false)
|
||||
{
|
||||
if ($reset || is_null($this->testResult)) {
|
||||
try {
|
||||
Log::resetTime(Log::LV_DEBUG);
|
||||
Log::info('START TEST "' . $this->getTitle() . '" [CLASS: ' . get_called_class() . ']');
|
||||
$this->testResult = $this->runTest();
|
||||
} catch (Exception $e) {
|
||||
Log::logException($e, Log::LV_DEFAULT, ' TEST "' . $this->getTitle() . '" EXCEPTION:');
|
||||
$this->testResult = self::LV_FAIL;
|
||||
} catch (Error $e) {
|
||||
Log::logException($e, Log::LV_DEFAULT, ' TEST "' . $this->getTitle() . '" EXCEPTION:');
|
||||
$this->testResult = self::LV_FAIL;
|
||||
}
|
||||
Log::logTime('TEST "' . $this->getTitle() . '" RESULT: ' . $this->resultString() . "\n", Log::LV_DEFAULT, false);
|
||||
}
|
||||
|
||||
return $this->testResult;
|
||||
}
|
||||
|
||||
abstract protected function runTest();
|
||||
|
||||
public function display()
|
||||
{
|
||||
if ($this->testResult === self::LV_SKIP) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function getCategory()
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Test class ' . get_called_class();
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
try {
|
||||
switch ($this->test(false)) {
|
||||
case self::LV_SKIP:
|
||||
return $this->skipContent();
|
||||
case self::LV_GOOD:
|
||||
return $this->goodContent();
|
||||
case self::LV_PASS:
|
||||
return $this->passContent();
|
||||
case self::LV_SOFT_WARNING:
|
||||
return $this->swarnContent();
|
||||
case self::LV_HARD_WARNING:
|
||||
return $this->hwarnContent();
|
||||
case self::LV_FAIL:
|
||||
default:
|
||||
return $this->failContent();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Log::logException($e, Log::LV_DEFAULT, 'VALIDATION DISPLAY CONTENT ' . get_called_class() . ' RESULT: ' . $this->resultString() . ' EXCEPTION:');
|
||||
return 'DISPLAY CONTENT PROBLEM <br>'
|
||||
. 'MESSAGE: ' . $e->getMessage() . '<br>'
|
||||
. 'TRACE:'
|
||||
. '<pre>' . $e->getTraceAsString() . '</pre>';
|
||||
} catch (Error $e) {
|
||||
Log::logException($e, Log::LV_DEFAULT, 'VALIDATION DISPLAY CONTENT ' . get_called_class() . ' ERROR:');
|
||||
return 'DISPLAY CONTENT PROBLEM <br>'
|
||||
. 'MESSAGE: ' . $e->getMessage() . '<br>'
|
||||
. 'TRACE:'
|
||||
. '<pre>' . $e->getTraceAsString() . '</pre>';
|
||||
}
|
||||
}
|
||||
|
||||
public function getBadgeClass()
|
||||
{
|
||||
return self::resultLevelToBadgeClass($this->test(false));
|
||||
}
|
||||
|
||||
public function getUniqueSelector()
|
||||
{
|
||||
return strtolower(str_replace("_", "-", get_called_class()));
|
||||
}
|
||||
|
||||
public function resultString()
|
||||
{
|
||||
return self::resultLevelToString($this->test(false));
|
||||
}
|
||||
|
||||
public static function resultLevelToString($level)
|
||||
{
|
||||
switch ($level) {
|
||||
case self::LV_SKIP:
|
||||
return 'skip';
|
||||
case self::LV_GOOD:
|
||||
return 'good';
|
||||
case self::LV_PASS:
|
||||
return 'passed';
|
||||
case self::LV_SOFT_WARNING:
|
||||
return 'soft warning';
|
||||
case self::LV_HARD_WARNING:
|
||||
return 'hard warning';
|
||||
case self::LV_FAIL:
|
||||
default:
|
||||
return 'failed';
|
||||
}
|
||||
}
|
||||
|
||||
public static function resultLevelToBadgeClass($level)
|
||||
{
|
||||
switch ($level) {
|
||||
case self::LV_SKIP:
|
||||
return '';
|
||||
case self::LV_GOOD:
|
||||
return 'good';
|
||||
case self::LV_PASS:
|
||||
return 'pass';
|
||||
case self::LV_SOFT_WARNING:
|
||||
return 'warn';
|
||||
case self::LV_HARD_WARNING:
|
||||
return 'hwarn';
|
||||
case self::LV_FAIL:
|
||||
default:
|
||||
return 'fail';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return content for test status: fail warning
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function failContent()
|
||||
{
|
||||
return 'test result: fail';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return content for test status: hard warning
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function hwarnContent()
|
||||
{
|
||||
return 'test result: hard warning';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return content for test status: soft warning
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function swarnContent()
|
||||
{
|
||||
return 'test result: soft warning';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return content for test status: good
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function goodContent()
|
||||
{
|
||||
return 'test result: good';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return content for test status: pass
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function passContent()
|
||||
{
|
||||
return 'test result: pass';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return content for test status: skip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function skipContent()
|
||||
{
|
||||
return 'test result: skipped';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,778 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Utils\Log\Log;
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
use Duplicator\Libs\Snap\SnapOS;
|
||||
|
||||
class DUPX_Validation_database_service
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var self
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var mysqli
|
||||
*/
|
||||
private $dbh = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $skipOtherTests = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $dbCreated = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (is_null(self::$instance)) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return mysqli <p>Returns an object which represents the connection to a MySQL Server.</p>
|
||||
*/
|
||||
public function getDbConnection()
|
||||
{
|
||||
if (is_null($this->dbh)) {
|
||||
$paramsManager = PrmMng::getInstance();
|
||||
|
||||
$this->dbh = DUPX_DB_Functions::getInstance()->dbConnection(array(
|
||||
'dbhost' => $paramsManager->getValue(PrmMng::PARAM_DB_HOST),
|
||||
'dbuser' => $paramsManager->getValue(PrmMng::PARAM_DB_USER),
|
||||
'dbpass' => $paramsManager->getValue(PrmMng::PARAM_DB_PASS),
|
||||
'dbname' => null
|
||||
));
|
||||
|
||||
if (empty($this->dbh)) {
|
||||
DUPX_DB_Functions::getInstance()->closeDbConnection();
|
||||
$this->dbh = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->dbh;
|
||||
}
|
||||
|
||||
/**
|
||||
* close db connection if is open
|
||||
*/
|
||||
public function closeDbConnection()
|
||||
{
|
||||
if (!is_null($this->dbh)) {
|
||||
mysqli_close($this->dbh);
|
||||
$this->dbh = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function setSkipOtherTests($skip = true)
|
||||
{
|
||||
$this->skipOtherTests = (bool) $skip;
|
||||
}
|
||||
|
||||
public function skipDatabaseTests()
|
||||
{
|
||||
return $this->skipOtherTests;
|
||||
}
|
||||
|
||||
public function databaseExists(&$errorMessage = null)
|
||||
{
|
||||
try {
|
||||
$result = true;
|
||||
|
||||
if (!$this->getDbConnection()) {
|
||||
throw new Exception('Database not connected');
|
||||
}
|
||||
|
||||
$paramsManager = PrmMng::getInstance();
|
||||
if (mysqli_select_db($this->dbh, $paramsManager->getValue(PrmMng::PARAM_DB_NAME)) !== true) {
|
||||
$errorMessage = mysqli_error($this->dbh);
|
||||
$result = false;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$errorMessage = $e->getMessage();
|
||||
Log::logException($e, Log::LV_DEFAULT, 'DATABASE SELECT EXCEPTION: ');
|
||||
$result = false;
|
||||
} catch (Error $e) {
|
||||
$errorMessage = $e->getMessage();
|
||||
Log::logException($e, Log::LV_DEFAULT, 'DATABASE SELECT EXCEPTION: ');
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function createDatabase(&$errorMessage = null)
|
||||
{
|
||||
if ($this->dbCreated) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
$result = true;
|
||||
|
||||
if (!$this->getDbConnection()) {
|
||||
throw new Exception('Database not connected');
|
||||
}
|
||||
|
||||
$dbName = PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_NAME);
|
||||
|
||||
switch (PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_VIEW_MODE)) {
|
||||
case 'basic':
|
||||
case 'cpnl':
|
||||
$query = 'CREATE DATABASE `' . mysqli_real_escape_string($this->dbh, $dbName) . '`';
|
||||
if (DUPX_DB::mysqli_query($this->dbh, $query) === false) {
|
||||
$errorMessage = mysqli_error($this->dbh);
|
||||
$result = false;
|
||||
}
|
||||
|
||||
if ($result && $this->databaseExists() === false) {
|
||||
$errorMessage = 'Can\'t select database after creation';
|
||||
$result = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$result = false;
|
||||
$errorMessage = 'Invalid db view mode';
|
||||
break;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$errorMessage = $e->getMessage();
|
||||
Log::logException($e, Log::LV_DEFAULT, 'DATABASE CREATE EXCEPTION: ');
|
||||
$result = false;
|
||||
} catch (Error $e) {
|
||||
$errorMessage = $e->getMessage();
|
||||
Log::logException($e, Log::LV_DEFAULT, 'DATABASE CREATE EXCEPTION: ');
|
||||
$result = false;
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
$this->dbCreated = true;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function isDatabaseCreated()
|
||||
{
|
||||
return $this->dbCreated;
|
||||
}
|
||||
|
||||
public function cleanUpDatabase(&$errorMessage = null)
|
||||
{
|
||||
if (!$this->dbCreated) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$result = true;
|
||||
|
||||
try {
|
||||
$dbName = PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_NAME);
|
||||
switch (PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_VIEW_MODE)) {
|
||||
case 'basic':
|
||||
case 'cpnl':
|
||||
//DELETE DB
|
||||
if (DUPX_DB::mysqli_query($this->dbh, "DROP DATABASE IF EXISTS `" . mysqli_real_escape_string($this->dbh, $dbName) . "`") === false) {
|
||||
$errorMessage = mysqli_error($this->dbh);
|
||||
$result = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$errorMessage = 'Invalid db view mode';
|
||||
$result = false;
|
||||
break;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$errorMessage = $e->getMessage();
|
||||
Log::logException($e, Log::LV_DEFAULT, 'DATABASE CLEANUP EXCEPTION: ');
|
||||
$result = false;
|
||||
} catch (Error $e) {
|
||||
$errorMessage = $e->getMessage();
|
||||
Log::logException($e, Log::LV_DEFAULT, 'DATABASE CLEANUP EXCEPTION: ');
|
||||
$result = false;
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
$this->dbCreated = false;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getDatabases()
|
||||
{
|
||||
if (!$this->getDbConnection()) {
|
||||
return array();
|
||||
}
|
||||
|
||||
switch (PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_VIEW_MODE)) {
|
||||
case 'basic':
|
||||
case 'cpnl':
|
||||
$dbUser = PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_USER);
|
||||
$host_user = substr_replace($dbUser, '', strpos($dbUser, '_'));
|
||||
break;
|
||||
default:
|
||||
return array();
|
||||
}
|
||||
return DUPX_DB::getDatabases($this->dbh, $host_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of tables that are affect by the DB action
|
||||
*
|
||||
* @param string|null $dbAction Adb action, if null get param db action
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getDBActionAffectedTables($dbAction = null)
|
||||
{
|
||||
if ($dbAction === null) {
|
||||
$dbAction = PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_ACTION);
|
||||
}
|
||||
|
||||
$affectedTables = array();
|
||||
$excludeTables = DUPX_DB_Functions::getExcludedTables();
|
||||
$escapedDbName = mysqli_real_escape_string($this->dbh, PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_NAME));
|
||||
$allTables = DUPX_DB::queryColumnToArray($this->dbh, 'SHOW TABLES FROM `' . $escapedDbName . '`');
|
||||
|
||||
switch ($dbAction) {
|
||||
case DUPX_DBInstall::DBACTION_EMPTY:
|
||||
case DUPX_DBInstall::DBACTION_RENAME:
|
||||
$affectedTables = array_diff($allTables, $excludeTables);
|
||||
break;
|
||||
case DUPX_DBInstall::DBACTION_REMOVE_ONLY_TABLES:
|
||||
$affectedTables = array_intersect(
|
||||
DUPX_DB_Tables::getInstance()->getNewTablesNames(),
|
||||
array_diff($allTables, $excludeTables)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return $affectedTables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of tables that are affect by the DB action
|
||||
*
|
||||
* @param string|null $dbAction Adb action, if null get param db action
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getDBActionAffectedTablesCount($dbAction = null)
|
||||
{
|
||||
$isCreateNewDatabase = PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_ACTION) == DUPX_DBInstall::DBACTION_CREATE;
|
||||
return ($isCreateNewDatabase) ? 0 : count($this->getDBActionAffectedTables($dbAction));
|
||||
}
|
||||
|
||||
|
||||
public function checkDbVisibility(&$errorMessage = null)
|
||||
{
|
||||
$result = true;
|
||||
|
||||
try {
|
||||
if (!$this->getDbConnection()) {
|
||||
throw new Exception('Database not connected');
|
||||
}
|
||||
|
||||
switch (PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_VIEW_MODE)) {
|
||||
case 'basic':
|
||||
case 'cpnl':
|
||||
$result = $this->databaseExists($errorMessage);
|
||||
break;
|
||||
default:
|
||||
$errorMessage = 'Invalid db view mode';
|
||||
$result = false;
|
||||
break;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$errorMessage = $e->getMessage();
|
||||
Log::logException($e, Log::LV_DEFAULT, 'DATABASE CHECK VISIBILITY EXCEPTION: ');
|
||||
$result = false;
|
||||
} catch (Error $e) {
|
||||
$errorMessage = $e->getMessage();
|
||||
Log::logException($e, Log::LV_DEFAULT, 'DATABASE CHECK VISIBILITY EXCEPTION: ');
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is validation test for "Prefix too long". Checks if there are
|
||||
* any new table names longer than 64 characters.
|
||||
*
|
||||
* @param string &$errorMessage // Will be filled with error message in case when validation test fails
|
||||
*
|
||||
* @return bool // Returns true if validation test passes, false otherwise
|
||||
*/
|
||||
public function checkDbPrefixTooLong(&$errorMessage = null)
|
||||
{
|
||||
$result = true;
|
||||
$numOfTooLongNewTableNames = count($this->getTooLongNewTableNames());
|
||||
if ($numOfTooLongNewTableNames > 0) {
|
||||
$errorMessage = "Length of $numOfTooLongNewTableNames table names exceeds limit of 64 after adding prefix.";
|
||||
$result = false;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of new table names whose length is bigger than 64 limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTooLongNewTableNames()
|
||||
{
|
||||
$tooLongNewTableNames = array();
|
||||
$newTableNames = array();
|
||||
$newTableNames = DUPX_DB_Tables::getInstance()->getNewTablesNames();
|
||||
for ($i = 0; $i < count($newTableNames); $i++) {
|
||||
if (strlen($newTableNames[$i]) > 64) {
|
||||
$tooLongNewTableNames[] = $newTableNames[$i];
|
||||
}
|
||||
}
|
||||
return $tooLongNewTableNames;
|
||||
}
|
||||
|
||||
public function dbTablesCount(&$errorMessage = null)
|
||||
{
|
||||
$result = true;
|
||||
|
||||
try {
|
||||
if (!$this->getDbConnection()) {
|
||||
throw new Exception('Database not connected');
|
||||
}
|
||||
|
||||
$dbName = PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_NAME);
|
||||
$result = DUPX_DB::countTables($this->dbh, $dbName);
|
||||
} catch (Exception $e) {
|
||||
$errorMessage = $e->getMessage();
|
||||
Log::logException($e, Log::LV_DEFAULT, 'DATABASE TABLES COUNT EXCEPTION: ');
|
||||
$result = false;
|
||||
} catch (Error $e) {
|
||||
$errorMessage = $e->getMessage();
|
||||
Log::logException($e, Log::LV_DEFAULT, 'DATABASE TABLES COUNT EXCEPTION: ');
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $perms
|
||||
* @param array $errorMessages
|
||||
*
|
||||
* @return int // test result level
|
||||
*/
|
||||
public function dbCheckUserPerms(&$perms = array(), &$errorMessages = array())
|
||||
{
|
||||
|
||||
$perms = array(
|
||||
'create' => DUPX_Validation_abstract_item::LV_SKIP,
|
||||
'insert' => DUPX_Validation_abstract_item::LV_SKIP,
|
||||
'select' => DUPX_Validation_abstract_item::LV_SKIP,
|
||||
'update' => DUPX_Validation_abstract_item::LV_SKIP,
|
||||
'delete' => DUPX_Validation_abstract_item::LV_SKIP,
|
||||
'drop' => DUPX_Validation_abstract_item::LV_SKIP,
|
||||
'view' => DUPX_Validation_abstract_item::LV_SKIP,
|
||||
'proc' => DUPX_Validation_abstract_item::LV_SKIP,
|
||||
'func' => DUPX_Validation_abstract_item::LV_SKIP,
|
||||
'trigger' => DUPX_Validation_abstract_item::LV_SKIP
|
||||
);
|
||||
|
||||
$errorMessages = array();
|
||||
try {
|
||||
if (!$this->getDbConnection()) {
|
||||
throw new Exception('Database not connected');
|
||||
}
|
||||
|
||||
$dbName = PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_NAME);
|
||||
|
||||
if (mysqli_select_db($this->dbh, $dbName) === false) {
|
||||
throw new Exception('Can\'t select database ' . $dbName);
|
||||
}
|
||||
|
||||
$tmpTable = '__dpro_temp_' . rand(1000, 9999) . '_' . date("ymdHis");
|
||||
$tmpTableEscaped = '`' . mysqli_real_escape_string($this->dbh, $tmpTable) . '`';
|
||||
|
||||
if (
|
||||
$this->isQueryWorking("CREATE TABLE " . $tmpTableEscaped . " ("
|
||||
. "`id` int(11) NOT NULL AUTO_INCREMENT, "
|
||||
. "`text` text NOT NULL, "
|
||||
. "PRIMARY KEY (`id`))", $errorMessages)
|
||||
) {
|
||||
$perms['create'] = DUPX_Validation_abstract_item::LV_PASS;
|
||||
} else {
|
||||
$perms['create'] = DUPX_Validation_abstract_item::LV_FAIL;
|
||||
}
|
||||
|
||||
if ($perms['create']) {
|
||||
if ($this->isQueryWorking("INSERT INTO " . $tmpTableEscaped . " (`text`) VALUES ('TEXT-1')", $errorMessages)) {
|
||||
$perms['insert'] = DUPX_Validation_abstract_item::LV_PASS;
|
||||
} else {
|
||||
$perms['insert'] = DUPX_Validation_abstract_item::LV_FAIL;
|
||||
}
|
||||
|
||||
if ($this->isQueryWorking("SELECT COUNT(*) FROM " . $tmpTableEscaped, $errorMessages)) {
|
||||
$perms['select'] = DUPX_Validation_abstract_item::LV_PASS;
|
||||
} else {
|
||||
$perms['select'] = DUPX_Validation_abstract_item::LV_FAIL;
|
||||
}
|
||||
|
||||
if ($this->isQueryWorking("UPDATE " . $tmpTableEscaped . " SET text = 'TEXT-2' WHERE text = 'TEXT-1'", $errorMessages)) {
|
||||
$perms['update'] = DUPX_Validation_abstract_item::LV_PASS;
|
||||
} else {
|
||||
$perms['update'] = DUPX_Validation_abstract_item::LV_FAIL;
|
||||
}
|
||||
|
||||
if ($this->isQueryWorking("DELETE FROM " . $tmpTableEscaped . " WHERE text = 'TEXT-2'", $errorMessages)) {
|
||||
$perms['delete'] = DUPX_Validation_abstract_item::LV_PASS;
|
||||
} else {
|
||||
$perms['delete'] = DUPX_Validation_abstract_item::LV_FAIL;
|
||||
}
|
||||
|
||||
if ($this->isQueryWorking("DROP TABLE IF EXISTS " . $tmpTableEscaped . ";", $errorMessages)) {
|
||||
$perms['drop'] = DUPX_Validation_abstract_item::LV_PASS;
|
||||
} else {
|
||||
$perms['drop'] = DUPX_Validation_abstract_item::LV_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->dbHasViews()) {
|
||||
if ($this->dbCheckGrants(array("CREATE VIEW"), $errorMessages)) {
|
||||
$perms['view'] = DUPX_Validation_abstract_item::LV_PASS;
|
||||
} else {
|
||||
$perms['view'] = DUPX_Validation_abstract_item::LV_HARD_WARNING;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->dbHasProcedures()) {
|
||||
if ($this->dbCheckGrants(array("CREATE ROUTINE", "ALTER ROUTINE"), $errorMessages)) {
|
||||
$perms['proc'] = DUPX_Validation_abstract_item::LV_PASS;
|
||||
} else {
|
||||
$perms['proc'] = DUPX_Validation_abstract_item::LV_HARD_WARNING;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->dbHasFunctions()) {
|
||||
if ($this->dbCheckGrants(array("CREATE ROUTINE", "ALTER ROUTINE"), $errorMessages)) {
|
||||
$perms['func'] = DUPX_Validation_abstract_item::LV_PASS;
|
||||
} else {
|
||||
$perms['func'] = DUPX_Validation_abstract_item::LV_HARD_WARNING;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->dbHasTriggers()) {
|
||||
if ($this->dbCheckGrants(array("TRIGGER"), $errorMessages)) {
|
||||
$perms['trigger'] = DUPX_Validation_abstract_item::LV_PASS;
|
||||
} else {
|
||||
$perms['trigger'] = DUPX_Validation_abstract_item::LV_SOFT_WARNING;
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$errorMessages[] = $e->getMessage();
|
||||
Log::logException($e, Log::LV_DEFAULT, 'DATABASE CHECK USER PERMS EXCEPTION: ');
|
||||
} catch (Error $e) {
|
||||
$errorMessages[] = $e->getMessage();
|
||||
Log::logException($e, Log::LV_DEFAULT, 'DATABASE CHECK USER PERMS EXCEPTION: ');
|
||||
}
|
||||
|
||||
return min($perms);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $query The SQL query
|
||||
* @param array $errorMessages Optionally you can capture the errors in this array
|
||||
*
|
||||
* @return boolean returns true if running the query did not fail
|
||||
*/
|
||||
public function isQueryWorking($query, &$errorMessages = array())
|
||||
{
|
||||
$result = true;
|
||||
|
||||
try {
|
||||
if (DUPX_DB::mysqli_query($this->dbh, $query) === false) {
|
||||
$currentError = mysqli_error($this->dbh);
|
||||
$result = false;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$currentError = $e->getMessage();
|
||||
Log::logException($e, Log::LV_DEFAULT, 'TESTING QUERY: ');
|
||||
$result = false;
|
||||
} catch (Error $e) {
|
||||
$currentError = $e->getMessage();
|
||||
Log::logException($e, Log::LV_DEFAULT, 'TESTING QUERY: ');
|
||||
$result = false;
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
$errorMessages[] = $currentError;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $grants // list of grants to check
|
||||
* @param array $errorMessages
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function dbCheckGrants($grants, &$errorMessages = array())
|
||||
{
|
||||
try {
|
||||
if (($queryResult = DUPX_DB::mysqli_query($this->dbh, "SHOW GRANTS")) === false) {
|
||||
$errorMessages[] = mysqli_error($this->dbh);
|
||||
return false;
|
||||
}
|
||||
|
||||
$dbName = PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_NAME);
|
||||
$regex = '/^GRANT\s+(?!USAGE)(.+)\s+ON\s+(\*|`.*?`)\..*$/';
|
||||
$matches = null;
|
||||
$matchFound = false;
|
||||
|
||||
while ($row = mysqli_fetch_array($queryResult)) {
|
||||
if (!preg_match($regex, $row[0], $matches)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
$matches['2'] === '*' ||
|
||||
$matches['2'] === $dbName ||
|
||||
$matches['2'] === addcslashes($dbName, '_%')
|
||||
) {
|
||||
Log::info('SHOW GRANTS CURRENT DB: ' . $row[0], Log::LV_DEBUG);
|
||||
$matchFound = true;
|
||||
break;
|
||||
}
|
||||
|
||||
//The GRANT queries can have wildcarsds in them which we have to take into account.
|
||||
//Turn wildcards into regex expressions and try matching the expression against the DB name.
|
||||
$dbNameRegex = preg_replace('/(?<!\\\\)%/', '.*', $matches['2']); // unescaped % becomes .*
|
||||
$dbNameRegex = preg_replace('/(?<!\\\\)_/', '.', $dbNameRegex); // unescaped _ becomes .
|
||||
if (preg_match($dbNameRegex, $dbName) === 1) {
|
||||
Log::info('Grant matched via Wildcard: ' . $dbNameRegex, Log::LV_DEBUG);
|
||||
Log::info('SHOW GRANTS CURRENT DB: ' . $row[0], Log::LV_DEBUG);
|
||||
$matchFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$matchFound) {
|
||||
Log::info('GRANTS LINE OF CURRENT DB NOT FOUND');
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($matches['1'] === 'ALL PRIVILEGES') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$userPrivileges = preg_split('/\s*,\s*/', $matches['1']);
|
||||
if (($notGrants = array_diff($grants, $userPrivileges))) {
|
||||
$message = "The mysql user does not have the '" . implode(', ', $notGrants) . "' permission.";
|
||||
Log::info('NO GRANTS: ' . $message);
|
||||
$errorMessages[] = $message;
|
||||
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$errorMessages[] = $e->getMessage();
|
||||
Log::logException($e, Log::LV_DEFAULT, 'DATABASE CHECK PERM EXCEPTION: ');
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function dbHasProcedures()
|
||||
{
|
||||
if (DUPX_ArchiveConfig::getInstance()->dbInfo->procCount > 0) {
|
||||
Log::info("SOURCE SITE DB HAD PROCEDURES", Log::LV_DEBUG);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (($result = DUPX_DB::mysqli_query($this->dbh, "SHOW PROCEDURE STATUS"))) {
|
||||
if (mysqli_num_rows($result) > 0) {
|
||||
Log::info("INSTALL SITE HAS PROCEDURES", Log::LV_DEBUG);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function dbHasFunctions()
|
||||
{
|
||||
if (DUPX_ArchiveConfig::getInstance()->dbInfo->funcCount > 0) {
|
||||
Log::info("SOURCE SITE DB HAD FUNCTIONS", Log::LV_DEBUG);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (($result = DUPX_DB::mysqli_query($this->dbh, "SHOW FUNCTION STATUS"))) {
|
||||
if (mysqli_num_rows($result) > 0) {
|
||||
Log::info("INSTALL SITE HAS FUNCTIONS", Log::LV_DEBUG);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function dbHasTriggers()
|
||||
{
|
||||
if (($result = DUPX_DB::mysqli_query($this->dbh, "SHOW TRIGGERS"))) {
|
||||
if (mysqli_num_rows($result) > 0) {
|
||||
Log::info("INSTALL SITE HAS TRIGGERS", Log::LV_DEBUG);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function dbHasViews()
|
||||
{
|
||||
if (DUPX_ArchiveConfig::getInstance()->dbInfo->viewCount > 0) {
|
||||
Log::info("SOURCE SITE DB HAD VIEWS", Log::LV_DEBUG);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (($result = DUPX_DB::mysqli_query($this->dbh, "SHOW FULL TABLES WHERE Table_Type = 'VIEW'"))) {
|
||||
if (mysqli_num_rows($result) > 0) {
|
||||
Log::info("INSTALL SITE HAS VIEWS", Log::LV_DEBUG);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function dbGtidModeEnabled(&$errorMessage = array())
|
||||
{
|
||||
try {
|
||||
$gtidModeEnabled = false;
|
||||
if (($result = DUPX_DB::mysqli_query($this->dbh, 'SELECT @@GLOBAL.GTID_MODE', Log::LV_DEBUG)) === false) {
|
||||
if (Log::isLevel(Log::LV_DEBUG)) {
|
||||
// It is normal for this query to generate an error when the GTID is not active. So normally it is better not to worry users with managed error messages.
|
||||
$errorMessage = mysqli_error($this->dbh);
|
||||
}
|
||||
} else {
|
||||
if (($row = mysqli_fetch_array($result, MYSQLI_NUM)) !== false) {
|
||||
if (strcasecmp($row[0], 'on') === 0) {
|
||||
$gtidModeEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = $gtidModeEnabled;
|
||||
} catch (Exception $e) {
|
||||
$errorMessage = $e->getMessage();
|
||||
Log::logException($e, Log::LV_DEFAULT, 'DATABASE CHECK CHARSET EXCEPTION: ');
|
||||
$result = false;
|
||||
} catch (Error $e) {
|
||||
$errorMessage = $e->getMessage();
|
||||
Log::logException($e, Log::LV_DEFAULT, 'DATABASE CHECK CHARSET EXCEPTION: ');
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $errorMessage
|
||||
*
|
||||
* @return int // -1 fail
|
||||
*/
|
||||
public function caseSensitiveTablesValue(&$errorMessage = array())
|
||||
{
|
||||
try {
|
||||
if (!$this->getDbConnection()) {
|
||||
throw new Exception('Database not connected');
|
||||
}
|
||||
|
||||
if (($lowerCaseTableNames = DUPX_DB::getVariable($this->dbh, 'lower_case_table_names')) === null) {
|
||||
if (SnapOS::isWindows()) {
|
||||
$lowerCaseTableNames = 1;
|
||||
} elseif (SnapOS::isOSX()) {
|
||||
$lowerCaseTableNames = 2;
|
||||
} else {
|
||||
$lowerCaseTableNames = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$result = $lowerCaseTableNames;
|
||||
} catch (Exception $e) {
|
||||
$errorMessage = $e->getMessage();
|
||||
Log::logException($e, Log::LV_DEFAULT, 'DATABASE CHECK CHARSET EXCEPTION: ');
|
||||
$result = -1;
|
||||
} catch (Error $e) {
|
||||
$errorMessage = $e->getMessage();
|
||||
Log::logException($e, Log::LV_DEFAULT, 'DATABASE CHECK CHARSET EXCEPTION: ');
|
||||
$result = -1;
|
||||
}
|
||||
|
||||
return (int) $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|false
|
||||
*/
|
||||
public function getUserResources()
|
||||
{
|
||||
try {
|
||||
$host = PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_HOST);
|
||||
$user = PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_USER);
|
||||
$query = "SELECT max_questions, max_updates, max_connections FROM mysql.user WHERE user = '{$user}' AND host = '{$host}'";
|
||||
|
||||
if (($result = DUPX_DB::mysqli_query($this->dbh, $query, Log::LV_DEFAULT)) != false && $result->num_rows > 0) {
|
||||
return $result->fetch_assoc();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Log::logException($e, Log::LV_DEFAULT, 'DATABASE CHECK USER RESOURCE EXCEPTION: ');
|
||||
} catch (Error $e) {
|
||||
Log::logException($e, Log::LV_DEFAULT, 'DATABASE CHECK USER RESOURCE ERROR: ');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function __clone()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Core\Bootstrap;
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
|
||||
require_once(DUPX_INIT . '/classes/validation/class.validation.database.service.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/class.validation.abstract.item.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.owrinstall.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.addon.sites.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.manual.extraction.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.dbonly.iswordpress.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.package.age.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.package.size.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.php.version.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.open.basedir.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.memory.limit.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.php.extensions.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.timeout.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.wordfence.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.disk.space.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.importer.version.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.importable.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.rest.api.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.managed.tprefix.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.iswritable.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.iswritable.configs.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.mysql.connect.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.tokenizer.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.replace.paths.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.managed.supported.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.siteground.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.archive.check.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/tests/class.validation.test.recovery.link.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/database-tests/class.validation.test.db.host.name.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/database-tests/class.validation.test.db.connection.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/database-tests/class.validation.test.db.version.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/database-tests/class.validation.test.db.create.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/database-tests/class.validation.test.db.cleanup.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/database-tests/class.validation.test.db.affected.tables.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/database-tests/class.validation.test.db.prefix.too.long.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/database-tests/class.validation.test.db.visibility.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/database-tests/class.validation.test.db.manual.tables.count.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/database-tests/class.validation.test.db.multiple.wp.installs.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/database-tests/class.validation.test.db.user.perms.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/database-tests/class.validation.test.db.user.resources.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/database-tests/class.validation.test.db.triggers.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/database-tests/class.validation.test.db.show.variables.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/database-tests/class.validation.test.db.supported.charset.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/database-tests/class.validation.test.db.supported.engine.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/database-tests/class.validation.test.db.gtid.mode.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/database-tests/class.validation.test.db.case.sentivie.tables.php');
|
||||
require_once(DUPX_INIT . '/classes/validation/database-tests/class.validation.test.db.supported.default.charset.php');
|
||||
|
||||
class DUPX_Validation_manager
|
||||
{
|
||||
const CAT_GENERAL = 'general';
|
||||
const CAT_FILESYSTEM = 'filesystem';
|
||||
const CAT_PHP = 'php';
|
||||
const CAT_DATABASE = 'database';
|
||||
const ACTION_ON_START_NORMAL = 'normal';
|
||||
const ACTION_ON_START_AUTO = 'auto';
|
||||
const MIN_LEVEL_VALID = 1; // DUPX_Validation_abstract_item::LV_HARD_WARNING, can't assign directly in php 5.3
|
||||
|
||||
/**
|
||||
*
|
||||
* @var self
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var DUPX_Validation_abstract_item[]
|
||||
*/
|
||||
private $tests = array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $extraData = array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (is_null(self::$instance)) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
/* GENERAL * */
|
||||
$this->tests[] = new DUPX_Validation_test_archive_check(self::CAT_GENERAL);
|
||||
$this->tests[] = new DUPX_Validation_test_importer_version(self::CAT_GENERAL);
|
||||
$this->tests[] = new DUPX_Validation_test_owrinstall(self::CAT_GENERAL);
|
||||
$this->tests[] = new DUPX_Validation_test_recovery(self::CAT_GENERAL);
|
||||
$this->tests[] = new DUPX_Validation_test_importable(self::CAT_GENERAL);
|
||||
$this->tests[] = new DUPX_Validation_test_rest_api(self::CAT_GENERAL);
|
||||
$this->tests[] = new DUPX_Validation_test_manual_extraction(self::CAT_GENERAL);
|
||||
$this->tests[] = new DUPX_Validation_test_dbonly_iswordpress(self::CAT_GENERAL);
|
||||
$this->tests[] = new DUPX_Validation_test_package_age(self::CAT_GENERAL);
|
||||
$this->tests[] = new DUPX_Validation_test_package_size(self::CAT_GENERAL);
|
||||
$this->tests[] = new DUPX_Validation_test_replace_paths(self::CAT_GENERAL);
|
||||
$this->tests[] = new DUPX_Validation_test_managed_supported(self::CAT_GENERAL);
|
||||
$this->tests[] = new DUPX_Validation_test_siteground(self::CAT_GENERAL);
|
||||
$this->tests[] = new DUPX_Validation_test_addon_sites(self::CAT_GENERAL);
|
||||
$this->tests[] = new DUPX_Validation_test_wordfence(self::CAT_GENERAL);
|
||||
$this->tests[] = new DUPX_Validation_test_managed_tprefix(self::CAT_GENERAL);
|
||||
|
||||
/* PHP * */
|
||||
$this->tests[] = new DUPX_Validation_test_php_version(self::CAT_PHP);
|
||||
$this->tests[] = new DUPX_Validation_test_open_basedir(self::CAT_PHP);
|
||||
$this->tests[] = new DUPX_Validation_test_memory_limit(self::CAT_PHP);
|
||||
$this->tests[] = new DUPX_Validation_test_extensions(self::CAT_PHP);
|
||||
$this->tests[] = new DUPX_Validation_test_mysql_connect(self::CAT_PHP);
|
||||
$this->tests[] = new DUPX_Validation_test_tokenizer(self::CAT_PHP);
|
||||
$this->tests[] = new DUPX_Validation_test_timeout(self::CAT_PHP);
|
||||
|
||||
/* FILESYSTEM * */
|
||||
$this->tests[] = new DUPX_Validation_test_disk_space(self::CAT_FILESYSTEM);
|
||||
$this->tests[] = new DUPX_Validation_test_iswritable(self::CAT_FILESYSTEM);
|
||||
$this->tests[] = new DUPX_Validation_test_iswritable_configs(self::CAT_FILESYSTEM);
|
||||
|
||||
/* DATABASE * */
|
||||
$this->tests[] = new DUPX_Validation_test_db_host_name(self::CAT_DATABASE);
|
||||
$this->tests[] = new DUPX_Validation_test_db_connection(self::CAT_DATABASE);
|
||||
$this->tests[] = new DUPX_Validation_test_db_version(self::CAT_DATABASE);
|
||||
$this->tests[] = new DUPX_Validation_test_db_create(self::CAT_DATABASE);
|
||||
$this->tests[] = new DUPX_Validation_test_db_supported_engine(self::CAT_DATABASE);
|
||||
$this->tests[] = new DUPX_Validation_test_db_gtid_mode(self::CAT_DATABASE);
|
||||
$this->tests[] = new DUPX_Validation_test_db_visibility(self::CAT_DATABASE);
|
||||
$this->tests[] = new DUPX_Validation_test_db_manual_tabels_count(self::CAT_DATABASE);
|
||||
$this->tests[] = new DUPX_Validation_test_db_multiple_wp_installs(self::CAT_DATABASE);
|
||||
$this->tests[] = new DUPX_Validation_test_db_user_resources(self::CAT_DATABASE);
|
||||
$this->tests[] = new DUPX_Validation_test_db_user_perms(self::CAT_DATABASE);
|
||||
$this->tests[] = new DUPX_Validation_test_db_custom_queries(self::CAT_DATABASE);
|
||||
$this->tests[] = new DUPX_Validation_test_db_triggers(self::CAT_DATABASE);
|
||||
$this->tests[] = new DUPX_Validation_test_db_supported_default_charset(self::CAT_DATABASE);
|
||||
$this->tests[] = new DUPX_Validation_test_db_supported_charset(self::CAT_DATABASE);
|
||||
$this->tests[] = new DUPX_Validation_test_db_case_sensitive_tables(self::CAT_DATABASE);
|
||||
$this->tests[] = new DUPX_Validation_test_db_affected_tables(self::CAT_DATABASE);
|
||||
$this->tests[] = new DUPX_Validation_test_db_prefix_too_long(self::CAT_DATABASE);
|
||||
|
||||
// after all database tests
|
||||
$this->tests[] = new DUPX_Validation_test_db_cleanup(self::CAT_DATABASE);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isValidated()
|
||||
{
|
||||
$paramsManager = PrmMng::getInstance();
|
||||
return $paramsManager->getValue(PrmMng::PARAM_VALIDATION_LEVEL) >= self::MIN_LEVEL_VALID;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isFirstValidationOnLoad()
|
||||
{
|
||||
return (
|
||||
Bootstrap::isInit() &&
|
||||
PrmMng::getInstance()->getValue(PrmMng::PARAM_VALIDATION_ACTION_ON_START) === DUPX_Validation_manager::ACTION_ON_START_AUTO
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function validateOnLoad()
|
||||
{
|
||||
$paramsManager = PrmMng::getInstance();
|
||||
if ($paramsManager->getValue(PrmMng::PARAM_VALIDATION_ACTION_ON_START) === DUPX_Validation_manager::ACTION_ON_START_AUTO) {
|
||||
return true;
|
||||
}
|
||||
if ($paramsManager->getValue(PrmMng::PARAM_STEP_ACTION) === DUPX_CTRL::ACTION_STEP_ON_VALIDATE) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getValidateData()
|
||||
{
|
||||
$this->runTests();
|
||||
$mainResult = $this->getMainResult();
|
||||
|
||||
$paramsManager = PrmMng::getInstance();
|
||||
$paramsManager->setValue(PrmMng::PARAM_VALIDATION_LEVEL, $mainResult);
|
||||
$paramsManager->save();
|
||||
|
||||
return array(
|
||||
'mainLevel' => $mainResult,
|
||||
'mainBagedClass' => DUPX_Validation_abstract_item::resultLevelToBadgeClass($mainResult),
|
||||
'mainText' => DUPX_Validation_abstract_item::resultLevelToString($mainResult),
|
||||
'categoriesLevels' => array(
|
||||
'database' => $this->getCagegoryResult(self::CAT_DATABASE),
|
||||
'php' => $this->getCagegoryResult(self::CAT_PHP),
|
||||
'general' => $this->getCagegoryResult(self::CAT_GENERAL),
|
||||
'filesystem' => $this->getCagegoryResult(self::CAT_FILESYSTEM)
|
||||
),
|
||||
'htmlResult' => DUPX_CTRL::renderPostProcessings($this->getValidationHtmlResult()),
|
||||
'extraData' => $this->extraData
|
||||
);
|
||||
}
|
||||
|
||||
protected function runTests()
|
||||
{
|
||||
$this->extraData = array();
|
||||
|
||||
foreach ($this->tests as $test) {
|
||||
$test->test(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getValidationHtmlResult()
|
||||
{
|
||||
return dupxTplRender('parts/validation/validation-result', array(
|
||||
'validationManager' => $this
|
||||
), false);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function addExtraData($key, $value)
|
||||
{
|
||||
$this->extraData[$key] = $value;
|
||||
}
|
||||
|
||||
public function getTestsCategory($category)
|
||||
{
|
||||
$result = array();
|
||||
foreach ($this->tests as $test) {
|
||||
if ($test->getCategory() === $category) {
|
||||
$result[] = $test;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getCagegoryResult($category)
|
||||
{
|
||||
$result = PHP_INT_MAX;
|
||||
foreach ($this->tests as $test) {
|
||||
if ($test->getCategory() === $category && $test->test() < $result) {
|
||||
$result = $test->test();
|
||||
}
|
||||
}
|
||||
if ($result === DUPX_Validation_abstract_item::LV_GOOD) {
|
||||
$result = DUPX_Validation_abstract_item::LV_PASS;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getCagegoryBadge($category)
|
||||
{
|
||||
return DUPX_Validation_abstract_item::resultLevelToBadgeClass($this->getCagegoryResult($category));
|
||||
}
|
||||
|
||||
public function getMainResult()
|
||||
{
|
||||
$result = PHP_INT_MAX;
|
||||
foreach ($this->tests as $test) {
|
||||
if ($test->test() < $result) {
|
||||
$result = $test->test();
|
||||
}
|
||||
}
|
||||
if ($result === DUPX_Validation_abstract_item::LV_GOOD) {
|
||||
$result = DUPX_Validation_abstract_item::LV_PASS;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Core\Params\Descriptors\ParamDescUsers;
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
use Duplicator\Installer\Utils\Log\Log;
|
||||
|
||||
class DUPX_Validation_test_db_affected_tables extends DUPX_Validation_abstract_item
|
||||
{
|
||||
const MAX_DISPLAY_TABLE_COUNT = 1000;
|
||||
|
||||
private $affectedTableCount = 0;
|
||||
private $affectedTables = array();
|
||||
private $message = "";
|
||||
private $isNewSubSite = false;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function runTest()
|
||||
{
|
||||
$dbAction = PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_ACTION);
|
||||
|
||||
if (
|
||||
DUPX_Validation_database_service::getInstance()->skipDatabaseTests()
|
||||
|| $dbAction === DUPX_DBInstall::DBACTION_MANUAL
|
||||
|| $dbAction === DUPX_DBInstall::DBACTION_CREATE
|
||||
) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
if (DUPX_Validation_database_service::getInstance()->dbTablesCount() === 0) {
|
||||
return self::LV_PASS;
|
||||
}
|
||||
|
||||
$this->affectedTables = DUPX_Validation_database_service::getInstance()->getDBActionAffectedTables($dbAction);
|
||||
$this->affectedTableCount = count($this->affectedTables);
|
||||
$partialText = $this->affectedTableCount > self::MAX_DISPLAY_TABLE_COUNT ? self::MAX_DISPLAY_TABLE_COUNT . " of " . $this->affectedTableCount : "All";
|
||||
|
||||
if ($dbAction === DUPX_DBInstall::DBACTION_REMOVE_ONLY_TABLES || $dbAction === DUPX_DBInstall::DBACTION_EMPTY) {
|
||||
$this->message = "{$partialText} tables flagged for <b>removal</b> are listed below:";
|
||||
} else {
|
||||
$this->message = "{$partialText} tables flagged for <b>back-up and rename</b> are listed below:";
|
||||
}
|
||||
|
||||
if ($this->affectedTableCount > 0) {
|
||||
return self::LV_SOFT_WARNING;
|
||||
}
|
||||
|
||||
return self::LV_PASS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Tables Flagged for Removal or Backup';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-affected-tables', array(
|
||||
'isOk' => true,
|
||||
'isNewSubSite' => $this->isNewSubSite
|
||||
), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-affected-tables', array(
|
||||
'isOk' => false,
|
||||
'message' => $this->message,
|
||||
'affectedTableCount' => $this->affectedTableCount,
|
||||
'affectedTables' => array_slice($this->affectedTables, 0, self::MAX_DISPLAY_TABLE_COUNT),
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
class DUPX_Validation_test_db_case_sensitive_tables extends DUPX_Validation_abstract_item
|
||||
{
|
||||
/** @var string */
|
||||
protected $errorMessage = '';
|
||||
|
||||
/** @var int<-1, max> */
|
||||
protected $lowerCaseTableNames = -1;
|
||||
|
||||
/** @var int<0, max> */
|
||||
protected $lowerCaseTableNamesSource = 0;
|
||||
|
||||
/** @var array<string[]> */
|
||||
protected $duplicateTables = array();
|
||||
|
||||
/** @var string[] */
|
||||
protected $redundantTables = array();
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
$archiveConfig = DUPX_ArchiveConfig::getInstance();
|
||||
$caseSensitiveTablePresent = $archiveConfig->isTablesCaseSensitive();
|
||||
if (DUPX_Validation_database_service::getInstance()->skipDatabaseTests() || !$caseSensitiveTablePresent) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
$this->duplicateTables = DUPX_ArchiveConfig::getInstance()->getDuplicateTableNames();
|
||||
$this->redundantTables = DUPX_ArchiveConfig::getInstance()->getRedundantDuplicateTableNames();
|
||||
$this->lowerCaseTableNames = DUPX_Validation_database_service::getInstance()->caseSensitiveTablesValue();
|
||||
$this->lowerCaseTableNamesSource = $archiveConfig->dbInfo->lowerCaseTableNames;
|
||||
$destIsCaseInsensitive = $this->lowerCaseTableNames !== 0;
|
||||
$sourceIsCaseSensitive = $this->lowerCaseTableNamesSource === 0;
|
||||
|
||||
if ($destIsCaseInsensitive && $sourceIsCaseSensitive && count($this->duplicateTables) > 0) {
|
||||
return self::LV_HARD_WARNING;
|
||||
}
|
||||
|
||||
if ($destIsCaseInsensitive) {
|
||||
return self::LV_SOFT_WARNING;
|
||||
}
|
||||
|
||||
return self::LV_PASS;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Tables Case Sensitivity';
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-case-sensitive-tables', array(
|
||||
'isOk' => false,
|
||||
'errorMessage' => $this->errorMessage,
|
||||
'lowerCaseTableNames' => $this->lowerCaseTableNames
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function hwarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-case-sensitive-duplicates', array(
|
||||
'lowerCaseTableNames' => $this->lowerCaseTableNames,
|
||||
'duplicateTableNames' => $this->duplicateTables,
|
||||
'reduntantTableNames' => $this->redundantTables
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-case-sensitive-tables', array(
|
||||
'isOk' => true,
|
||||
'errorMessage' => $this->errorMessage,
|
||||
'lowerCaseTableNames' => $this->lowerCaseTableNames
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
|
||||
class DUPX_Validation_test_db_cleanup extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected $errorMessage = '';
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if (DUPX_Validation_database_service::getInstance()->isDatabaseCreated() === false) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
if (DUPX_Validation_database_service::getInstance()->cleanUpDatabase($this->errorMessage)) {
|
||||
return self::LV_PASS;
|
||||
} else {
|
||||
return self::LV_HARD_WARNING;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Database cleanup';
|
||||
}
|
||||
|
||||
protected function hwarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-cleanup', array(
|
||||
'isOk' => false,
|
||||
'dbname' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_NAME),
|
||||
'isCpanel' => false,
|
||||
'errorMessage' => $this->errorMessage
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-cleanup', array(
|
||||
'isOk' => true,
|
||||
'dbname' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_NAME),
|
||||
'isCpanel' => false,
|
||||
'errorMessage' => $this->errorMessage
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
|
||||
class DUPX_Validation_test_db_connection extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected function runTest()
|
||||
{
|
||||
if (DUPX_Validation_database_service::getInstance()->skipDatabaseTests()) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
DUPX_Validation_database_service::getInstance()->setSkipOtherTests(true);
|
||||
if (DUPX_Validation_database_service::getInstance()->getDbConnection() === false) {
|
||||
return self::LV_FAIL;
|
||||
} else {
|
||||
DUPX_Validation_database_service::getInstance()->setSkipOtherTests(false);
|
||||
return self::LV_PASS;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Host Connection';
|
||||
}
|
||||
|
||||
protected function failContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-connection', array(
|
||||
'isOk' => false,
|
||||
'dbhost' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_HOST),
|
||||
'dbuser' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_USER),
|
||||
'dbpass' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_PASS),
|
||||
'mysqlConnErr' => mysqli_connect_error()
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-connection', array(
|
||||
'isOk' => true,
|
||||
'dbhost' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_HOST),
|
||||
'dbuser' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_USER),
|
||||
'dbpass' => '*****',
|
||||
'mysqlConnErr' => ''
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
|
||||
class DUPX_Validation_test_db_create extends DUPX_Validation_abstract_item
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $alreadyExists = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $errorMessage = '';
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if (
|
||||
DUPX_Validation_database_service::getInstance()->skipDatabaseTests() ||
|
||||
PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_ACTION) !== DUPX_DBInstall::DBACTION_CREATE
|
||||
) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
// already exists test
|
||||
if (DUPX_Validation_database_service::getInstance()->databaseExists()) {
|
||||
$this->errorMessage = 'Database already exists';
|
||||
$this->alreadyExists = true;
|
||||
return self::LV_FAIL;
|
||||
}
|
||||
|
||||
if (DUPX_Validation_database_service::getInstance()->createDatabase($this->errorMessage) === false) {
|
||||
return self::LV_FAIL;
|
||||
}
|
||||
|
||||
return self::LV_PASS;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Create New Database';
|
||||
}
|
||||
|
||||
protected function failContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-create', array(
|
||||
'isOk' => false,
|
||||
'alreadyExists' => $this->alreadyExists,
|
||||
'errorMessage' => $this->errorMessage,
|
||||
'isCpanel' => false,
|
||||
'dbname' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_NAME)
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-create', array(
|
||||
'isOk' => true,
|
||||
'alreadyExists' => $this->alreadyExists,
|
||||
'errorMessage' => $this->errorMessage,
|
||||
'isCpanel' => false,
|
||||
'dbname' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_NAME)
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
class DUPX_Validation_test_db_gtid_mode extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected $errorMessage = '';
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if (DUPX_Validation_database_service::getInstance()->skipDatabaseTests()) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
if (DUPX_Validation_database_service::getInstance()->dbGtidModeEnabled($this->errorMessage)) {
|
||||
return self::LV_SOFT_WARNING;
|
||||
} else {
|
||||
return self::LV_PASS;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Database GTID Mode';
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-gtid-mode', array(
|
||||
'isOk' => false,
|
||||
'errorMessage' => $this->errorMessage
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-gtid-mode', array(
|
||||
'isOk' => true,
|
||||
'errorMessage' => $this->errorMessage
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
use Duplicator\Libs\Snap\SnapIO;
|
||||
|
||||
class DUPX_Validation_test_db_host_name extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected $fixedHost = '';
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if (DUPX_Validation_database_service::getInstance()->skipDatabaseTests()) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
DUPX_Validation_database_service::getInstance()->setSkipOtherTests(true);
|
||||
|
||||
$host = PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_HOST);
|
||||
//Host check
|
||||
$parsed_host_info = DUPX_DB::parseDBHost($host);
|
||||
$parsed_host = $parsed_host_info[0];
|
||||
$isInvalidHost = $parsed_host == 'http' || $parsed_host == "https";
|
||||
|
||||
if ($isInvalidHost) {
|
||||
$this->fixedHost = SnapIO::untrailingslashit(str_replace($parsed_host . "://", "", $host));
|
||||
return self::LV_FAIL;
|
||||
} else {
|
||||
DUPX_Validation_database_service::getInstance()->setSkipOtherTests(false);
|
||||
return self::LV_PASS;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Host Name';
|
||||
}
|
||||
|
||||
protected function failContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-host-name', array(
|
||||
'isOk' => false,
|
||||
'host' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_HOST),
|
||||
'fixedHost' => $this->fixedHost
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-host-name', array(
|
||||
'isOk' => true,
|
||||
'host' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_HOST),
|
||||
'fixedHost' => ''
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
|
||||
class DUPX_Validation_test_db_manual_tabels_count extends DUPX_Validation_abstract_item
|
||||
{
|
||||
const MIN_TABLES_NUM = 10;
|
||||
|
||||
protected $errorMessage = '';
|
||||
protected $numTables = 0;
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if (
|
||||
DUPX_Validation_database_service::getInstance()->skipDatabaseTests() ||
|
||||
PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_ACTION) !== DUPX_DBInstall::DBACTION_MANUAL
|
||||
) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
$this->numTables = DUPX_Validation_database_service::getInstance()->dbTablesCount($this->errorMessage);
|
||||
|
||||
if ($this->numTables >= self::MIN_TABLES_NUM) {
|
||||
return self::LV_PASS;
|
||||
} else {
|
||||
return self::LV_HARD_WARNING;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Manual Table Check';
|
||||
}
|
||||
|
||||
protected function hwarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-manual-tables-count', array(
|
||||
'isOk' => false,
|
||||
'dbname' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_NAME),
|
||||
'numTables' => $this->numTables,
|
||||
'minNumTables' > self::MIN_TABLES_NUM,
|
||||
'errorMessage' => $this->errorMessage
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-manual-tables-count', array(
|
||||
'isOk' => true,
|
||||
'dbname' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_NAME),
|
||||
'numTables' => $this->numTables,
|
||||
'minNumTables' > self::MIN_TABLES_NUM,
|
||||
'errorMessage' => $this->errorMessage
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
use Duplicator\Libs\Snap\SnapWP;
|
||||
|
||||
class DUPX_Validation_test_db_multiple_wp_installs extends DUPX_Validation_abstract_item
|
||||
{
|
||||
/**
|
||||
* @var string[] unique wp prefixes in the DB
|
||||
*/
|
||||
protected $uniquePrefixes = array();
|
||||
|
||||
/**
|
||||
* Check mutiple db install in database
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function runTest()
|
||||
{
|
||||
$dbAction = PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_ACTION);
|
||||
if (
|
||||
DUPX_Validation_database_service::getInstance()->skipDatabaseTests()
|
||||
|| $dbAction === DUPX_DBInstall::DBACTION_MANUAL
|
||||
|| $dbAction === DUPX_DBInstall::DBACTION_CREATE
|
||||
) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
if (DUPX_Validation_database_service::getInstance()->dbTablesCount() === 0) {
|
||||
return self::LV_PASS;
|
||||
}
|
||||
|
||||
$affectedTables = DUPX_Validation_database_service::getInstance()->getDBActionAffectedTables($dbAction);
|
||||
$this->uniquePrefixes = SnapWP::getUniqueWPTablePrefixes($affectedTables);
|
||||
|
||||
if (count($this->uniquePrefixes) > 1) {
|
||||
return self::LV_SOFT_WARNING;
|
||||
}
|
||||
|
||||
return self::LV_PASS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get test title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Multiple WordPress Installs';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return content for test status: soft warning
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-multiple-wp-installs', array(
|
||||
'isOk' => false,
|
||||
'uniquePrefixes' => $this->uniquePrefixes
|
||||
), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return content for test status: pass
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-multiple-wp-installs', array(
|
||||
'isOk' => true,
|
||||
'uniquePrefixes' => $this->uniquePrefixes
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
|
||||
class DUPX_Validation_test_db_prefix_too_long extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected $errorMessage = '';
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if (DUPX_Validation_database_service::getInstance()->skipDatabaseTests()) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
DUPX_Validation_database_service::getInstance()->setSkipOtherTests(true);
|
||||
if (DUPX_Validation_database_service::getInstance()->checkDbPrefixTooLong($this->errorMessage)) {
|
||||
DUPX_Validation_database_service::getInstance()->setSkipOtherTests(false);
|
||||
return self::LV_PASS;
|
||||
} else {
|
||||
return self::LV_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Prefix too long';
|
||||
}
|
||||
|
||||
protected function failContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-prefix-too-long', array(
|
||||
'isOk' => false,
|
||||
'errorMessage' => $this->errorMessage,
|
||||
'tooLongNewTableNames' => DUPX_Validation_database_service::getInstance()->getTooLongNewTableNames()
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-prefix-too-long', array(
|
||||
'isOk' => true,
|
||||
'errorMessage' => $this->errorMessage,
|
||||
'tooLongNewTableNames' => DUPX_Validation_database_service::getInstance()->getTooLongNewTableNames()
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
class DUPX_Validation_test_db_custom_queries extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected function runTest()
|
||||
{
|
||||
if (DUPX_Validation_database_service::getInstance()->skipDatabaseTests()) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
if (!DUPX_Validation_database_service::getInstance()->isQueryWorking('SHOW VARIABLES LIKE "version"')) {
|
||||
return self::LV_FAIL;
|
||||
}
|
||||
|
||||
return self::LV_PASS;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return "Privileges: 'Show Variables' Query";
|
||||
}
|
||||
|
||||
protected function failContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-show-variables', array(
|
||||
'pass' => false
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-show-variables', array(
|
||||
'pass' => true
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
class DUPX_Validation_test_db_supported_charset extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected $errorMessage = '';
|
||||
protected $charsetsList = array();
|
||||
protected $collationsList = array();
|
||||
protected $invalidCharsets = array();
|
||||
protected $invalidCollations = array();
|
||||
protected $extraData = array();
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if (DUPX_Validation_database_service::getInstance()->skipDatabaseTests()) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
try {
|
||||
$archiveConfig = DUPX_ArchiveConfig::getInstance();
|
||||
|
||||
$this->charsetsList = $archiveConfig->dbInfo->charSetList;
|
||||
$this->collationsList = $archiveConfig->dbInfo->collationList;
|
||||
$this->invalidCharsets = $archiveConfig->invalidCharsets();
|
||||
$this->invalidCollations = $archiveConfig->invalidCollations();
|
||||
|
||||
if (empty($this->invalidCharsets) && empty($this->invalidCollations)) {
|
||||
return self::LV_PASS;
|
||||
} else {
|
||||
return self::LV_HARD_WARNING;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->errorMessage = $e->getMessage();
|
||||
return self::LV_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Character Set and Collation Capability';
|
||||
}
|
||||
|
||||
protected function failContent()
|
||||
{
|
||||
$dbFuncs = DUPX_DB_Functions::getInstance();
|
||||
|
||||
return dupxTplRender('parts/validation/database-tests/db-supported-charset', array(
|
||||
'testResult' => $this->testResult,
|
||||
'extraData' => $this->extraData,
|
||||
'charsetsList' => $this->charsetsList,
|
||||
'collationsList' => $this->collationsList,
|
||||
'invalidCharsets' => $this->invalidCharsets,
|
||||
'invalidCollations' => $this->invalidCollations,
|
||||
'usedCharset' => $dbFuncs->getRealCharsetByParam(),
|
||||
'usedCollate' => $dbFuncs->getRealCollateByParam(),
|
||||
'errorMessage' => $this->errorMessage
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function hwarnContent()
|
||||
{
|
||||
return $this->failContent();
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return $this->failContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
class DUPX_Validation_test_db_supported_default_charset extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected $errorMessage = '';
|
||||
protected $charsetOk = true;
|
||||
protected $collateOk = true;
|
||||
protected $sourceCharset = null;
|
||||
protected $sourceCollate = null;
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if (DUPX_Validation_database_service::getInstance()->skipDatabaseTests()) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
try {
|
||||
$archiveConfig = DUPX_ArchiveConfig::getInstance();
|
||||
$dbFuncs = DUPX_DB_Functions::getInstance();
|
||||
$this->sourceCharset = $archiveConfig->getWpConfigDefineValue('DB_CHARSET', '');
|
||||
$this->sourceCollate = $archiveConfig->getWpConfigDefineValue('DB_COLLATE', '');
|
||||
$data = $dbFuncs->getCharsetAndCollationData();
|
||||
|
||||
if (!array_key_exists($this->sourceCharset, $data)) {
|
||||
$this->charsetOk = false;
|
||||
} elseif (strlen($this->sourceCollate) > 0 && !in_array($this->sourceCollate, $data[$this->sourceCharset]['collations'])) {
|
||||
$this->collateOk = false;
|
||||
}
|
||||
|
||||
if ($this->charsetOk && $this->collateOk) {
|
||||
return self::LV_PASS;
|
||||
} else {
|
||||
return self::LV_SOFT_WARNING;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->errorMessage = $e->getMessage();
|
||||
return self::LV_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Character Set and Collation Support';
|
||||
}
|
||||
|
||||
protected function failContent()
|
||||
{
|
||||
$dbFuncs = DUPX_DB_Functions::getInstance();
|
||||
|
||||
return dupxTplRender('parts/validation/database-tests/db-supported-default-charset', array(
|
||||
'testResult' => $this->testResult,
|
||||
'charsetOk' => $this->charsetOk,
|
||||
'collateOk' => $this->collateOk,
|
||||
'sourceCharset' => $this->sourceCharset,
|
||||
'sourceCollate' => $this->sourceCollate,
|
||||
'usedCharset' => $dbFuncs->getRealCharsetByParam(),
|
||||
'usedCollate' => $dbFuncs->getRealCollateByParam(),
|
||||
'errorMessage' => $this->errorMessage
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return $this->failContent();
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return $this->failContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
class DUPX_Validation_test_db_supported_engine extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected $errorMessage = '';
|
||||
protected $invalidEngines = array();
|
||||
protected $defaultEngine = "";
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if (DUPX_Validation_database_service::getInstance()->skipDatabaseTests()) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->invalidEngines = DUPX_ArchiveConfig::getInstance()->invalidEngines();
|
||||
$this->defaultEngine = DUPX_DB_Functions::getInstance()->getDefaultEngine();
|
||||
|
||||
if (empty($this->invalidEngines)) {
|
||||
return self::LV_PASS;
|
||||
} else {
|
||||
return self::LV_HARD_WARNING;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->errorMessage = $e->getMessage();
|
||||
return self::LV_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Database Engine Support';
|
||||
}
|
||||
|
||||
protected function failContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-supported-engine', array(
|
||||
'testResult' => $this->testResult,
|
||||
'invalidEngines' => $this->invalidEngines,
|
||||
'defaultEngine' => $this->defaultEngine,
|
||||
'errorMessage' => $this->errorMessage
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function hwarnContent()
|
||||
{
|
||||
return $this->failContent();
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return $this->failContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
class DUPX_Validation_test_db_triggers extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected $triggers = array();
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if (DUPX_Validation_database_service::getInstance()->skipDatabaseTests()) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
$this->triggers = (array)DUPX_ArchiveConfig::getInstance()->dbInfo->triggerList;
|
||||
if (count($this->triggers) > 0) {
|
||||
return self::LV_SOFT_WARNING;
|
||||
}
|
||||
|
||||
return self::LV_PASS;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Source Database Triggers';
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-triggers', array(
|
||||
'isOk' => true,
|
||||
'triggers' => $this->triggers,
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-triggers', array(
|
||||
'isOk' => false,
|
||||
'triggers' => $this->triggers,
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
|
||||
class DUPX_Validation_test_db_user_perms extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected $perms = array();
|
||||
protected $errorMessages = array();
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if (DUPX_Validation_database_service::getInstance()->skipDatabaseTests()) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
return DUPX_Validation_database_service::getInstance()->dbCheckUserPerms($this->perms, $this->errorMessages);
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Privileges: User Table Access';
|
||||
}
|
||||
|
||||
protected function failContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-user-perms', array(
|
||||
'testResult' => self::LV_FAIL,
|
||||
'perms' => $this->perms,
|
||||
'failedPerms' => array_keys($this->perms, false, true),
|
||||
'dbname' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_NAME),
|
||||
'dbuser' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_USER),
|
||||
'errorMessages' => $this->errorMessages
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-user-perms', array(
|
||||
'testResult' => self::LV_PASS,
|
||||
'perms' => $this->perms,
|
||||
'dbname' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_NAME),
|
||||
'dbuser' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_USER),
|
||||
'errorMessages' => $this->errorMessages
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-user-perms', array(
|
||||
'testResult' => self::LV_HARD_WARNING,
|
||||
'perms' => $this->perms,
|
||||
'dbname' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_NAME),
|
||||
'dbuser' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_USER),
|
||||
'errorMessages' => $this->errorMessages
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function hwarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-user-perms', array(
|
||||
'testResult' => self::LV_HARD_WARNING,
|
||||
'perms' => $this->perms,
|
||||
'dbname' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_NAME),
|
||||
'dbuser' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_USER),
|
||||
'errorMessages' => $this->errorMessages
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Libs\Snap\SnapUtil;
|
||||
|
||||
class DUPX_Validation_test_db_user_resources extends DUPX_Validation_abstract_item
|
||||
{
|
||||
private $userResources = array();
|
||||
private $userHasRestrictedResource = false;
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if (DUPX_Validation_database_service::getInstance()->skipDatabaseTests()) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
if (($this->userResources = DUPX_Validation_database_service::getInstance()->getUserResources()) !== false) {
|
||||
$this->userHasRestrictedResource = SnapUtil::inArrayExtended($this->userResources, function ($value) {
|
||||
return $value > 0;
|
||||
});
|
||||
}
|
||||
|
||||
if ($this->userHasRestrictedResource) {
|
||||
return self::LV_SOFT_WARNING;
|
||||
}
|
||||
|
||||
return self::LV_PASS;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Privileges: User Resources';
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-user-resources', array(
|
||||
'isOk' => !$this->userHasRestrictedResource,
|
||||
'userResources' => $this->userResources,
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-user-resources', array(
|
||||
'isOk' => !$this->userHasRestrictedResource,
|
||||
'userResources' => $this->userResources,
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Utils\Log\Log;
|
||||
use Duplicator\Libs\Snap\SnapDB;
|
||||
|
||||
class DUPX_Validation_test_db_version extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected $sourceDBVersion = null;
|
||||
protected $hostDBVersion = null;
|
||||
protected $hostDBEngine = null;
|
||||
protected $sourceDBEngine = null;
|
||||
protected $dbsOfSameType = true;
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if (DUPX_Validation_database_service::getInstance()->skipDatabaseTests()) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
DUPX_Validation_database_service::getInstance()->setSkipOtherTests(true);
|
||||
|
||||
$this->hostDBVersion = DUPX_DB::getVersion(DUPX_Validation_database_service::getInstance()->getDbConnection());
|
||||
$this->sourceDBVersion = DUPX_ArchiveConfig::getInstance()->version_db;
|
||||
Log::info('Current DB version: ' . Log::v2str($this->hostDBVersion) . ' Source DB version: ' . Log::v2str($this->sourceDBVersion), Log::LV_DETAILED);
|
||||
|
||||
if (version_compare($this->hostDBVersion, '5.0.0', '<')) {
|
||||
return self::LV_FAIL;
|
||||
}
|
||||
|
||||
DUPX_Validation_database_service::getInstance()->setSkipOtherTests(false);
|
||||
$this->hostDBEngine = SnapDB::getDBEngine(DUPX_Validation_database_service::getInstance()->getDbConnection());
|
||||
$this->sourceDBEngine = DUPX_ArchiveConfig::getInstance()->dbInfo->dbEngine;
|
||||
$this->dbsOfSameType = $this->sourceDBEngine === $this->hostDBEngine;
|
||||
|
||||
if (!$this->dbsOfSameType || intval($this->hostDBVersion) < intval($this->sourceDBVersion)) {
|
||||
return self::LV_SOFT_WARNING;
|
||||
}
|
||||
|
||||
return self::LV_PASS;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Database Version';
|
||||
}
|
||||
|
||||
protected function failContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-version', array(
|
||||
'isOk' => false,
|
||||
'hostDBVersion' => $this->hostDBVersion,
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-version-swarn', array(
|
||||
'hostDBVersion' => $this->hostDBVersion,
|
||||
'sourceDBVersion' => $this->sourceDBVersion,
|
||||
'hostDBEngine' => $this->hostDBEngine,
|
||||
'sourceDBEngine' => $this->sourceDBEngine,
|
||||
'dbsOfSameType' => $this->dbsOfSameType
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-version', array(
|
||||
'isOk' => true,
|
||||
'hostDBVersion' => $this->hostDBVersion,
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
|
||||
class DUPX_Validation_test_db_visibility extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected $errorMessage = '';
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if (DUPX_Validation_database_service::getInstance()->skipDatabaseTests()) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
DUPX_Validation_database_service::getInstance()->setSkipOtherTests(true);
|
||||
if (DUPX_Validation_database_service::getInstance()->checkDbVisibility($this->errorMessage)) {
|
||||
DUPX_Validation_database_service::getInstance()->setSkipOtherTests(false);
|
||||
return self::LV_PASS;
|
||||
} else {
|
||||
return self::LV_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Privileges: User Visibility';
|
||||
}
|
||||
|
||||
protected function failContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-visibility', array(
|
||||
'isOk' => false,
|
||||
'databases' => DUPX_Validation_database_service::getInstance()->getDatabases(),
|
||||
'dbname' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_NAME),
|
||||
'dbuser' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_USER),
|
||||
'errorMessage' => $this->errorMessage
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/database-tests/db-visibility', array(
|
||||
'isOk' => true,
|
||||
'databases' => DUPX_Validation_database_service::getInstance()->getDatabases(),
|
||||
'dbname' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_NAME),
|
||||
'dbuser' => PrmMng::getInstance()->getValue(PrmMng::PARAM_DB_USER),
|
||||
'errorMessage' => $this->errorMessage
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
|
||||
class DUPX_Validation_test_addon_sites extends DUPX_Validation_abstract_item
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function runTest()
|
||||
{
|
||||
$list = self::getAddonsListsFolders();
|
||||
|
||||
if (PrmMng::getInstance()->getValue(PrmMng::PARAM_ARCHIVE_ACTION) === DUP_Extraction::ACTION_DO_NOTHING) {
|
||||
return self::LV_GOOD;
|
||||
}
|
||||
|
||||
if (count($list) > 0) {
|
||||
return self::LV_SOFT_WARNING;
|
||||
} else {
|
||||
return self::LV_GOOD;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @staticvar string[] $addonListFolder
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getAddonsListsFolders()
|
||||
{
|
||||
static $addonListFolder = null;
|
||||
if (is_null($addonListFolder)) {
|
||||
$addonListFolder = DUPX_Server::getWpAddonsSiteLists();
|
||||
}
|
||||
return $addonListFolder;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Addon Sites';
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/addon-sites', array(
|
||||
'testResult' => $this->testResult,
|
||||
'pathsList' => self::getAddonsListsFolders()
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function goodContent()
|
||||
{
|
||||
return $this->swarnContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
class DUPX_Validation_test_archive_check extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected function runTest()
|
||||
{
|
||||
if (DUPX_Conf_Utils::isConfArkPresent()) {
|
||||
if (DUPX_Conf_Utils::archiveExists()) {
|
||||
return self::LV_PASS;
|
||||
} else {
|
||||
return self::LV_SOFT_WARNING;
|
||||
}
|
||||
} else {
|
||||
return self::LV_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Archive Check';
|
||||
}
|
||||
|
||||
protected function failContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/archive-check', array(
|
||||
'testResult' => $this->testResult
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return $this->failContent();
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return $this->failContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
class DUPX_Validation_test_dbonly_iswordpress extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected function runTest()
|
||||
{
|
||||
if (!DUPX_ArchiveConfig::getInstance()->exportOnlyDB) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
if (DUPX_Server::isWordPress()) {
|
||||
return self::LV_GOOD;
|
||||
} else {
|
||||
return self::LV_SOFT_WARNING;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Database Only';
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/dbonly-iswordpress', array(), false);
|
||||
}
|
||||
|
||||
protected function goodContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/dbonly-iswordpress', array(), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
use Duplicator\Installer\Models\ScanInfo;
|
||||
use Duplicator\Libs\Snap\SnapIO;
|
||||
|
||||
class DUPX_Validation_test_disk_space extends DUPX_Validation_abstract_item
|
||||
{
|
||||
private $freeSpace = 0;
|
||||
private $archiveSize = 0;
|
||||
private $extractedSize = 0;
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if (!function_exists('disk_free_space')) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
// if home path is root path is necessary do a trailingslashit
|
||||
$realPath = SnapIO::safePathTrailingslashit(PrmMng::getInstance()->getValue(PrmMng::PARAM_PATH_NEW));
|
||||
$this->freeSpace = @disk_free_space($realPath);
|
||||
$this->archiveSize = DUPX_Conf_Utils::archiveExists() ? DUPX_Conf_Utils::archiveSize() : 1;
|
||||
$this->extractedSize = ScanInfo::getInstance()->getUSize();
|
||||
|
||||
if ($this->freeSpace && $this->archiveSize > 0 && $this->freeSpace > ($this->extractedSize + $this->archiveSize)) {
|
||||
return self::LV_GOOD;
|
||||
} else {
|
||||
return self::LV_SOFT_WARNING;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Disk Space';
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/diskspace', array(
|
||||
'freeSpace' => DUPX_U::readableByteSize($this->freeSpace),
|
||||
'requiredSpace' => DUPX_U::readableByteSize($this->archiveSize + $this->extractedSize),
|
||||
'isOk' => false
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function goodContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/diskspace', array(
|
||||
'freeSpace' => DUPX_U::readableByteSize($this->freeSpace),
|
||||
'requiredSpace' => DUPX_U::readableByteSize($this->archiveSize + $this->extractedSize),
|
||||
'isOk' => true
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Models\ScanInfo;
|
||||
|
||||
class DUPX_Validation_test_importable extends DUPX_Validation_abstract_item
|
||||
{
|
||||
/** @var string */
|
||||
protected $failMessage = '';
|
||||
|
||||
/**
|
||||
* Run test
|
||||
*
|
||||
* @return int test status enum
|
||||
*/
|
||||
protected function runTest()
|
||||
{
|
||||
if (DUPX_InstallerState::isClassicInstall()) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
$archiveConf = DUPX_ArchiveConfig::getInstance();
|
||||
|
||||
$coreFoldersCheck = false;
|
||||
$subsitesCheck = false;
|
||||
$globalTablesCheck = false;
|
||||
|
||||
switch (DUPX_InstallerState::getInstType()) {
|
||||
case DUPX_InstallerState::INSTALL_SINGLE_SITE:
|
||||
case DUPX_InstallerState::INSTALL_RBACKUP_SINGLE_SITE:
|
||||
$coreFoldersCheck = true;
|
||||
$globalTablesCheck = true;
|
||||
break;
|
||||
case DUPX_InstallerState::INSTALL_SINGLE_SITE_ON_SUBDOMAIN:
|
||||
case DUPX_InstallerState::INSTALL_SINGLE_SITE_ON_SUBFOLDER:
|
||||
$globalTablesCheck = true;
|
||||
break;
|
||||
case DUPX_InstallerState::INSTALL_NOT_SET:
|
||||
default:
|
||||
throw new Exception('Unknown mode');
|
||||
}
|
||||
|
||||
if ($subsitesCheck) {
|
||||
for ($i = 0; $i < count($archiveConf->subsites); $i++) {
|
||||
if (
|
||||
empty($archiveConf->subsites[$i]->filteredTables) &&
|
||||
empty($archiveConf->subsites[$i]->filteredPaths)
|
||||
) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($i >= count($archiveConf->subsites)) {
|
||||
$this->failMessage = 'The package does not have any importable subsite.';
|
||||
return self::LV_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
if ($coreFoldersCheck) {
|
||||
if (ScanInfo::getInstance()->hasFilteredCoreFolders()) {
|
||||
$this->failMessage = 'The package is missing WordPress core folder(s)! ' .
|
||||
'It must include wp-admin, wp-content, wp-includes, uploads, plugins, and themes folders.';
|
||||
return self::LV_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
if ($globalTablesCheck) {
|
||||
if ($archiveConf->dbInfo->tablesBaseCount != $archiveConf->dbInfo->tablesFinalCount) {
|
||||
$this->failMessage = 'The package is missing some of the site tables.';
|
||||
return self::LV_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
return self::LV_PASS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get test title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Package is Importable';
|
||||
}
|
||||
|
||||
/**
|
||||
* Render fail content
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function failContent()
|
||||
{
|
||||
return dupxTplRender(
|
||||
'parts/validation/tests/importable-package',
|
||||
array(
|
||||
'testResult' => $this->testResult,
|
||||
'failMessage' => $this->failMessage
|
||||
),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return $this->failContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
use Duplicator\Libs\Snap\SnapUtil;
|
||||
|
||||
class DUPX_Validation_test_importer_version extends DUPX_Validation_abstract_item
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function runTest()
|
||||
{
|
||||
|
||||
if (!DUPX_InstallerState::isImportFromBackendMode()) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
$overwriteData = PrmMng::getInstance()->getValue(PrmMng::PARAM_OVERWRITE_SITE_DATA);
|
||||
if (SnapUtil::versionCompare($overwriteData['dupVersion'], DUPX_VERSION, '<', 3)) {
|
||||
return self::LV_FAIL;
|
||||
}
|
||||
|
||||
return self::LV_PASS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return test ticekt
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Duplicator importer version';
|
||||
}
|
||||
|
||||
protected function failContent()
|
||||
{
|
||||
$overwriteData = PrmMng::getInstance()->getValue(PrmMng::PARAM_OVERWRITE_SITE_DATA);
|
||||
|
||||
return dupxTplRender('parts/validation/tests/importer-version', array(
|
||||
'testResult' => $this->testResult,
|
||||
'importerVer' => ($overwriteData['dupVersion'] == '0' ? 'Unknown' : $overwriteData['dupVersion'])
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return $this->failContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
use Duplicator\Libs\Snap\SnapIO;
|
||||
|
||||
class DUPX_Validation_test_iswritable_configs extends DUPX_Validation_abstract_item
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var bool[]
|
||||
*/
|
||||
protected $configsCheck = array(
|
||||
'wpconfig' => false,
|
||||
'htaccess' => false,
|
||||
'other' => false
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $notWritableConfigsList = array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected function runTest()
|
||||
{
|
||||
$this->configsCheck = self::configsWritableChecks();
|
||||
|
||||
foreach ($this->configsCheck as $check) {
|
||||
if ($check === false) {
|
||||
if (
|
||||
DUPX_InstallerState::isRestoreBackup() ||
|
||||
DUPX_Custom_Host_Manager::getInstance()->isManaged() !== false
|
||||
) {
|
||||
return self::LV_SOFT_WARNING;
|
||||
} else {
|
||||
return self::LV_HARD_WARNING;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return self::LV_PASS;
|
||||
}
|
||||
|
||||
/**
|
||||
* try to set wigth config permission and check if configs files are writeable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function configsWritableChecks()
|
||||
{
|
||||
$result = array();
|
||||
// if home path is root path is necessary do a trailingslashit
|
||||
$homePath = SnapIO::safePathTrailingslashit(PrmMng::getInstance()->getValue(PrmMng::PARAM_PATH_NEW));
|
||||
|
||||
if (!SnapIO::dirAddFullPermsAndCheckResult($homePath)) {
|
||||
$result['wpconfig'] = false;
|
||||
$result['htaccess'] = false;
|
||||
$result['other'] = false;
|
||||
} else {
|
||||
$configFile = $homePath . 'wp-config.php';
|
||||
if (file_exists($configFile)) {
|
||||
$result['wpconfig'] = SnapIO::fileAddFullPermsAndCheckResult($configFile);
|
||||
} else {
|
||||
$result['wpconfig'] = true;
|
||||
}
|
||||
|
||||
$configFile = $homePath . '.htaccess';
|
||||
if (file_exists($configFile)) {
|
||||
$result['htaccess'] = SnapIO::fileAddFullPermsAndCheckResult($configFile);
|
||||
} else {
|
||||
$result['htaccess'] = true;
|
||||
}
|
||||
|
||||
$result['other'] = true;
|
||||
$configFile = $homePath . 'web.config';
|
||||
if (file_exists($configFile) && !SnapIO::fileAddFullPermsAndCheckResult($configFile)) {
|
||||
$result['other'] = false;
|
||||
}
|
||||
|
||||
$configFile = $homePath . '.user.ini';
|
||||
if (file_exists($configFile) && !SnapIO::fileAddFullPermsAndCheckResult($configFile)) {
|
||||
$result['other'] = false;
|
||||
}
|
||||
|
||||
$configFile = $homePath . 'php.ini';
|
||||
if (file_exists($configFile) && !SnapIO::fileAddFullPermsAndCheckResult($configFile)) {
|
||||
$result['other'] = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Permissions: Configs Files ';
|
||||
}
|
||||
|
||||
protected function hwarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/configs-is-writable', array(
|
||||
'testResult' => $this->testResult,
|
||||
'configsCheck' => $this->configsCheck
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return $this->hwarnContent();
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return $this->hwarnContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
use Duplicator\Libs\Snap\SnapIO;
|
||||
use Duplicator\Libs\Snap\SnapWP;
|
||||
|
||||
class DUPX_Validation_test_iswritable extends DUPX_Validation_abstract_item
|
||||
{
|
||||
const TEMP_PHP_FILE_NAME = 'dup_tmp_php_file_test.php';
|
||||
|
||||
/** @var string[] */
|
||||
protected $faildDirPerms = array();
|
||||
|
||||
/** @var array */
|
||||
protected $phpPerms = array();
|
||||
|
||||
/**
|
||||
* Runs Test
|
||||
*
|
||||
* @return int
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function runTest()
|
||||
{
|
||||
$this->faildDirPerms = $this->checkWritePermissions();
|
||||
$testPass = (count($this->faildDirPerms) == 0);
|
||||
|
||||
$prmMng = PrmMng::getInstance();
|
||||
if ($prmMng->getValue(PrmMng::PARAM_ARCHIVE_ENGINE_SKIP_WP_FILES) === DUP_Extraction::FILTER_NONE) {
|
||||
$abspath = $prmMng->getValue(PrmMng::PARAM_PATH_WP_CORE_NEW);
|
||||
$this->phpPerms = array(
|
||||
array(
|
||||
'dir' => $abspath . '/wp-admin',
|
||||
'pass' => false,
|
||||
'message' => ''
|
||||
),
|
||||
array(
|
||||
'dir' => $abspath . '/wp-includes',
|
||||
'pass' => false,
|
||||
'message' => ''
|
||||
)
|
||||
);
|
||||
|
||||
for ($i = 0; $i < count($this->phpPerms); $i++) {
|
||||
$this->phpPerms[$i]['pass'] = self::checkPhpFileCreation(
|
||||
$this->phpPerms[$i]['dir'],
|
||||
$this->phpPerms[$i]['message']
|
||||
);
|
||||
|
||||
if ($this->phpPerms[$i]['pass'] == false) {
|
||||
$testPass = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($testPass) {
|
||||
return self::LV_PASS;
|
||||
} else {
|
||||
if (DUPX_Custom_Host_Manager::getInstance()->isManaged()) {
|
||||
return self::LV_SOFT_WARNING;
|
||||
} else {
|
||||
return self::LV_HARD_WARNING;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of paths that we don't have "write" permissions on
|
||||
*
|
||||
* @return string[]
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function checkWritePermissions()
|
||||
{
|
||||
$prmMng = PrmMng::getInstance();
|
||||
$failResult = array();
|
||||
$dirFiles = DUPX_Package::getDirsListPath();
|
||||
$archiveConfig = DUPX_ArchiveConfig::getInstance();
|
||||
$skipWpCore = ($prmMng->getValue(PrmMng::PARAM_ARCHIVE_ENGINE_SKIP_WP_FILES) !== DUP_Extraction::FILTER_NONE);
|
||||
|
||||
if (($handle = fopen($dirFiles, "r")) === false) {
|
||||
throw new Exception('Can\'t open dirs file list');
|
||||
}
|
||||
|
||||
while (($line = fgets($handle)) !== false) {
|
||||
if (($info = json_decode($line)) === null) {
|
||||
throw new Exception('Invalid json line in dirs file: ' . $line);
|
||||
}
|
||||
if ($skipWpCore && SnapWP::isWpCore($info->p, SnapWP::PATH_RELATIVE)) {
|
||||
continue;
|
||||
}
|
||||
$destPath = $archiveConfig->destFileFromArchiveName($info->p);
|
||||
if (file_exists($destPath) && !SnapIO::dirAddFullPermsAndCheckResult($destPath)) {
|
||||
$failResult[] = $destPath;
|
||||
}
|
||||
}
|
||||
fclose($handle);
|
||||
return $failResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if PHP files can be creatend in passed folder
|
||||
*
|
||||
* @param string $dir folder to check
|
||||
* @param string $message error message
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected static function checkPhpFileCreation($dir, &$message = '')
|
||||
{
|
||||
$removeDir = false;
|
||||
$exception = null;
|
||||
|
||||
try {
|
||||
if (!file_exists($dir)) {
|
||||
if (!SnapIO::mkdirP($dir)) {
|
||||
throw new Exception('Don\'t have permissition to create folder "' . $dir . '"');
|
||||
}
|
||||
$removeDir = true;
|
||||
} elseif (!is_dir($dir)) {
|
||||
throw new Exception('"' . $dir . '" must be a folder');
|
||||
} elseif (!is_writable($dir) || !is_executable($dir)) {
|
||||
if (SnapIO::chmod($dir, 'u+rwx') == false) {
|
||||
throw new Exception('"' . $dir . '" don\'t have write permissions');
|
||||
}
|
||||
}
|
||||
|
||||
$tmpFile = SnapIO::trailingslashit($dir) . self::TEMP_PHP_FILE_NAME;
|
||||
|
||||
if (file_exists($tmpFile) && unlink($tmpFile) == false) {
|
||||
throw new Exception('Can\'t remove temp php file \"' . $tmpFile . '\" to check if php files are writable');
|
||||
}
|
||||
|
||||
if (file_put_contents($tmpFile, "<?php\n\n//silent") == false) {
|
||||
throw new Exception('Cannot create PHP files even if the "' . basename($dir) . '" folder has permissions');
|
||||
}
|
||||
|
||||
unlink($tmpFile);
|
||||
} catch (Exception $e) {
|
||||
$exception = $e;
|
||||
}
|
||||
|
||||
if ($removeDir) {
|
||||
rmdir($dir);
|
||||
}
|
||||
|
||||
if (is_null($exception)) {
|
||||
return true;
|
||||
} else {
|
||||
$message = $exception->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Permissions: General';
|
||||
}
|
||||
|
||||
protected function hwarnContent()
|
||||
{
|
||||
$result = dupxTplRender('parts/validation/tests/writeable-checks', array(
|
||||
'testResult' => $this->testResult,
|
||||
'phpPerms' => $this->phpPerms,
|
||||
'faildDirPerms' => $this->faildDirPerms
|
||||
), false);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return $this->hwarnContent();
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return $this->hwarnContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
class DUPX_Validation_test_managed_supported extends DUPX_Validation_abstract_item
|
||||
{
|
||||
private $managed = false;
|
||||
private $failMessage = '';
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if (!($this->managed = DUPX_Custom_Host_Manager::getInstance()->isManaged())) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
if (DUPX_InstallerState::isImportFromBackendMode()) {
|
||||
return self::LV_PASS;
|
||||
}
|
||||
|
||||
switch ($this->managed) {
|
||||
case DUPX_Custom_Host_Manager::HOST_GODADDY:
|
||||
case DUPX_Custom_Host_Manager::HOST_LIQUIDWEB:
|
||||
case DUPX_Custom_Host_Manager::HOST_WPENGINE:
|
||||
return self::LV_PASS;
|
||||
case DUPX_Custom_Host_Manager::HOST_PANTHEON:
|
||||
case DUPX_Custom_Host_Manager::HOST_WORDPRESSCOM:
|
||||
case DUPX_Custom_Host_Manager::HOST_FLYWHEEL:
|
||||
$this->failMessage = 'Standard installations on this managed host are not supported because it uses a non-standard configuration that can ' .
|
||||
'only be read at runtime. Use Drop and Drop install to overwrite the site instead.';
|
||||
return self::LV_FAIL;
|
||||
default:
|
||||
$this->failMessage = "Unknown managed host type.";
|
||||
return self::LV_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Managed hosting supported';
|
||||
}
|
||||
|
||||
protected function failContent()
|
||||
{
|
||||
return dupxTplRender(
|
||||
'parts/validation/tests/managed-supported',
|
||||
array(
|
||||
'isOk' => false,
|
||||
'managedHosting' => $this->managed,
|
||||
'failMessage' => $this->failMessage
|
||||
),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender(
|
||||
'parts/validation/tests/managed-supported',
|
||||
array(
|
||||
'isOk' => true,
|
||||
'managedHosting' => $this->managed,
|
||||
'failMessage' => $this->failMessage
|
||||
),
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
|
||||
class DUPX_Validation_test_managed_tprefix extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected function runTest()
|
||||
{
|
||||
if (!DUPX_Custom_Host_Manager::getInstance()->isManaged()) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
$overwriteData = PrmMng::getInstance()->getValue(PrmMng::PARAM_OVERWRITE_SITE_DATA);
|
||||
if (DUPX_ArchiveConfig::getInstance()->wp_tableprefix != $overwriteData['table_prefix']) {
|
||||
return self::LV_SOFT_WARNING;
|
||||
} else {
|
||||
return self::LV_GOOD;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Table prefix of managed hosting';
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/managed-tprefix', array(
|
||||
'isOk' => false
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function goodContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/managed-tprefix', array(
|
||||
'isOk' => true
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
class DUPX_Validation_test_manual_extraction extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected function runTest()
|
||||
{
|
||||
if (DUPX_Conf_Utils::isManualExtractFilePresent()) {
|
||||
return self::LV_SOFT_WARNING;
|
||||
} else {
|
||||
return self::LV_GOOD;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Manual extraction detected';
|
||||
}
|
||||
|
||||
public function display()
|
||||
{
|
||||
if ($this->testResult === self::LV_SKIP) {
|
||||
return false;
|
||||
} else {
|
||||
return DUPX_Conf_Utils::isManualExtractFilePresent();
|
||||
}
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/manual-extraction', array(), false);
|
||||
}
|
||||
|
||||
protected function goodContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/manual-extraction', array(), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Libs\Snap\SnapUtil;
|
||||
|
||||
class DUPX_Validation_test_memory_limit extends DUPX_Validation_abstract_item
|
||||
{
|
||||
const MIN_MEMORY_LIMIT = '256M';
|
||||
|
||||
private $memoryLimit = false;
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if (($this->memoryLimit = @ini_get('memory_limit')) === false || empty($this->memoryLimit)) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
$this->memoryLimit = is_numeric($this->memoryLimit) ? DUPX_U::readableByteSize($this->memoryLimit) : $this->memoryLimit;
|
||||
if (SnapUtil::convertToBytes($this->memoryLimit) >= SnapUtil::convertToBytes(self::MIN_MEMORY_LIMIT)) {
|
||||
return self::LV_GOOD;
|
||||
}
|
||||
|
||||
return self::LV_SOFT_WARNING;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'PHP Memory Limit';
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/memory-limit', array(
|
||||
'memoryLimit' => $this->memoryLimit,
|
||||
'minMemoryLimit' => self::MIN_MEMORY_LIMIT,
|
||||
'isOk' => false
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function goodContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/memory-limit', array(
|
||||
'memoryLimit' => $this->memoryLimit,
|
||||
'minMemoryLimit' => self::MIN_MEMORY_LIMIT,
|
||||
'isOk' => true
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
class DUPX_Validation_test_mysql_connect extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected function runTest()
|
||||
{
|
||||
if (function_exists('mysqli_connect')) {
|
||||
return self::LV_PASS;
|
||||
} else {
|
||||
return self::LV_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'PHP Mysqli';
|
||||
}
|
||||
|
||||
protected function failContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/mysql-connect', array(), false);
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/mysql-connect', array(), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Libs\Snap\SnapIO;
|
||||
|
||||
class DUPX_Validation_test_open_basedir extends DUPX_Validation_abstract_item
|
||||
{
|
||||
private $openBaseDirEnabled = false;
|
||||
private $pathsOutsideOpenBaseDir = array();
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if (($this->openBaseDirEnabled = SnapIO::isOpenBaseDirEnabled()) === false) {
|
||||
return self::LV_GOOD;
|
||||
}
|
||||
|
||||
$archivePaths = array();
|
||||
$pathMapping = DUPX_ArchiveConfig::getInstance()->getPathsMapping();
|
||||
if (is_array($pathMapping)) {
|
||||
$archivePaths = $pathMapping;
|
||||
} else {
|
||||
$archivePaths[] = $pathMapping;
|
||||
}
|
||||
|
||||
foreach ($archivePaths as $archivePath) {
|
||||
if (SnapIO::getOpenBaseDirRootOfPath($archivePath) === false) {
|
||||
$this->pathsOutsideOpenBaseDir[] = $archivePath;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($this->pathsOutsideOpenBaseDir)) {
|
||||
return self::LV_GOOD;
|
||||
} else {
|
||||
return self::LV_HARD_WARNING;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'PHP Open Base';
|
||||
}
|
||||
|
||||
protected function hwarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/open-basedir', array(
|
||||
'openBaseDirEnabled' => $this->openBaseDirEnabled,
|
||||
'pathsOutsideOpenBaseDir' => $this->pathsOutsideOpenBaseDir,
|
||||
'isOk' => false
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function goodContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/open-basedir', array(
|
||||
'openBaseDirEnabled' => $this->openBaseDirEnabled,
|
||||
'pathsOutsideOpenBaseDir' => $this->pathsOutsideOpenBaseDir,
|
||||
'isOk' => true
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
class DUPX_Validation_test_owrinstall extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected function runTest()
|
||||
{
|
||||
if (
|
||||
DUPX_InstallerState::getInstance()->getMode() !== DUPX_InstallerState::MODE_OVR_INSTALL ||
|
||||
DUPX_InstallerState::isImportFromBackendMode()
|
||||
) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
if (DUPX_InstallerState::getInstance()->getMode() === DUPX_InstallerState::MODE_OVR_INSTALL) {
|
||||
return self::LV_SOFT_WARNING;
|
||||
} else {
|
||||
return self::LV_GOOD;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Overwrite Install';
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/overwrite-install', array(), false);
|
||||
}
|
||||
|
||||
protected function goodContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/overwrite-install', array(), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
class DUPX_Validation_test_package_age extends DUPX_Validation_abstract_item
|
||||
{
|
||||
const PACKAGE_DAYS_BEFORE_WARNING = 180;
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if ($this->getPackageDays() <= self::PACKAGE_DAYS_BEFORE_WARNING) {
|
||||
return self::LV_GOOD;
|
||||
} else {
|
||||
return self::LV_SOFT_WARNING;
|
||||
}
|
||||
}
|
||||
|
||||
protected function getPackageDays()
|
||||
{
|
||||
return round((time() - strtotime(DUPX_ArchiveConfig::getInstance()->created)) / 86400);
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Package Age';
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/package-age', array(
|
||||
'packageDays' => $this->getPackageDays(),
|
||||
'maxPackageDays' => self::PACKAGE_DAYS_BEFORE_WARNING
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function goodContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/package-age', array(
|
||||
'packageDays' => $this->getPackageDays(),
|
||||
'maxPackageDays' => self::PACKAGE_DAYS_BEFORE_WARNING
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
class DUPX_Validation_test_package_size extends DUPX_Validation_abstract_item
|
||||
{
|
||||
const PACKAGE_SIZE_BEFORE_WARNING_MB = 500;
|
||||
|
||||
private $packageSize = 0;
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
$this->packageSize = DUPX_Conf_Utils::archiveSize();
|
||||
if ($this->packageSize <= self::PACKAGE_SIZE_BEFORE_WARNING_MB * 1024 * 1024) {
|
||||
return self::LV_GOOD;
|
||||
} else {
|
||||
return self::LV_SOFT_WARNING;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Package Size';
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/package-size', array(
|
||||
'packageSize' => DUPX_U::readableByteSize($this->packageSize),
|
||||
'maxPackageSize' => self::PACKAGE_SIZE_BEFORE_WARNING_MB
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function goodContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/package-size', array(
|
||||
'packageSize' => DUPX_U::readableByteSize($this->packageSize),
|
||||
'maxPackageSize' => self::PACKAGE_SIZE_BEFORE_WARNING_MB
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Utils\Log\Log;
|
||||
|
||||
class DUPX_Validation_test_extensions extends DUPX_Validation_abstract_item
|
||||
{
|
||||
public $extensionTests = array(
|
||||
"json" => array(
|
||||
"failLevel" => self::LV_FAIL,
|
||||
"pass" => false
|
||||
)
|
||||
);
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
$result = self::LV_GOOD;
|
||||
foreach ($this->extensionTests as $extensionName => $extensionTest) {
|
||||
$this->extensionTests[$extensionName]["pass"] = extension_loaded($extensionName);
|
||||
if (!$this->extensionTests[$extensionName]["pass"]) {
|
||||
Log::info("The '{$extensionName}' extension is not loaded.");
|
||||
//update fail level
|
||||
if ($extensionTest["failLevel"] < $result) {
|
||||
$result = $extensionTest["failLevel"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'PHP Extensions';
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/php-extensions', array(
|
||||
'extensionTests' => $this->extensionTests
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function hwarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/php-extensions', array(
|
||||
'extensionTests' => $this->extensionTests
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function failContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/php-extensions', array(
|
||||
'extensionTests' => $this->extensionTests
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function goodContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/php-extensions', array(
|
||||
'extensionTests' => $this->extensionTests
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
class DUPX_Validation_test_php_version extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected function runTest()
|
||||
{
|
||||
$archiveConfig = DUPX_ArchiveConfig::getInstance();
|
||||
if ($archiveConfig->exportOnlyDB) {
|
||||
return self::LV_GOOD;
|
||||
}
|
||||
|
||||
// compare only major version ex 5 and 7 not 5.6 and 5.5
|
||||
if (intval($archiveConfig->version_php) === intval(phpversion())) {
|
||||
return self::LV_GOOD;
|
||||
} elseif (DUPX_InstallerState::isImportFromBackendMode()) {
|
||||
return self::LV_HARD_WARNING;
|
||||
} else {
|
||||
return self::LV_SOFT_WARNING;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'PHP Version Mismatch';
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/php-version', array(
|
||||
'fromPhp' => DUPX_ArchiveConfig::getInstance()->version_php,
|
||||
'toPhp' => phpversion(),
|
||||
'isOk' => false
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function hwarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/php-version', array(
|
||||
'fromPhp' => DUPX_ArchiveConfig::getInstance()->version_php,
|
||||
'toPhp' => phpversion(),
|
||||
'isOk' => false
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function goodContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/php-version', array(
|
||||
'fromPhp' => DUPX_ArchiveConfig::getInstance()->version_php,
|
||||
'toPhp' => phpversion(),
|
||||
'isOk' => true
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
|
||||
class DUPX_Validation_test_recovery extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected $importSiteInfo = array();
|
||||
protected $recoveryPage = false;
|
||||
protected $importPage = false;
|
||||
protected $recoveryIsOutToDate = false;
|
||||
protected $recoveryPackageLife = -1;
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
$paramsManager = PrmMng::getInstance();
|
||||
if (!DUPX_InstallerState::isImportFromBackendMode()) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
$this->importSiteInfo = PrmMng::getInstance()->getValue(PrmMng::PARAM_FROM_SITE_IMPORT_INFO);
|
||||
$this->importPage = $this->importSiteInfo['import_page'];
|
||||
$this->recoveryPage = $this->importSiteInfo['recovery_page'];
|
||||
$this->recoveryIsOutToDate = $this->importSiteInfo['recovery_is_out_to_date'];
|
||||
$this->recoveryPackageLife = $this->importSiteInfo['recovery_package_life'];
|
||||
|
||||
$recoveryLink = $paramsManager->getValue(PrmMng::PARAM_RECOVERY_LINK);
|
||||
if (empty($recoveryLink)) {
|
||||
return self::LV_HARD_WARNING;
|
||||
} else {
|
||||
if ($this->importSiteInfo['recovery_is_out_to_date']) {
|
||||
return self::LV_SOFT_WARNING;
|
||||
} else {
|
||||
return self::LV_GOOD;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Recovery Point';
|
||||
}
|
||||
|
||||
protected function hwarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/recovery', array(
|
||||
'testResult' => $this->testResult,
|
||||
'importPage' => $this->importPage,
|
||||
'recoveryPage' => $this->recoveryPage,
|
||||
'recoveryIsOutToDate' => $this->recoveryIsOutToDate,
|
||||
'recoveryPackageLife' => $this->recoveryPackageLife
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/recovery', array(
|
||||
'testResult' => $this->testResult,
|
||||
'importPage' => $this->importPage,
|
||||
'recoveryPage' => $this->recoveryPage,
|
||||
'recoveryIsOutToDate' => $this->recoveryIsOutToDate,
|
||||
'recoveryPackageLife' => $this->recoveryPackageLife
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function goodContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/recovery', array(
|
||||
'testResult' => $this->testResult,
|
||||
'importPage' => $this->importPage,
|
||||
'recoveryPage' => $this->recoveryPage,
|
||||
'recoveryIsOutToDate' => $this->recoveryIsOutToDate,
|
||||
'recoveryPackageLife' => $this->recoveryPackageLife
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
|
||||
class DUPX_Validation_test_replace_paths extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected $message = '';
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
$paramsManager = PrmMng::getInstance();
|
||||
|
||||
if (
|
||||
$paramsManager->getValue(PrmMng::PARAM_REPLACE_ENGINE) === DUPX_S3_Funcs::MODE_SKIP ||
|
||||
$paramsManager->getValue(PrmMng::PARAM_SKIP_PATH_REPLACE) === false
|
||||
) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
$archivePaths = DUPX_ArchiveConfig::getInstance()->getRealValue("archivePaths");
|
||||
if (strlen($archivePaths->home) == 0) {
|
||||
// if new path is equal at old path the replace isn't necessary so skip message
|
||||
if (strlen($paramsManager->getValue(PrmMng::PARAM_PATH_NEW)) === 0) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
$this->message = "It was found that the home path of the source was equal to '/'. In this case it's" .
|
||||
" impossible to automatically replace paths, because of that path replacements have been disabled.";
|
||||
}
|
||||
|
||||
return self::LV_HARD_WARNING;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Replace PATHs in database';
|
||||
}
|
||||
|
||||
protected function hwarnContent()
|
||||
{
|
||||
return dupxTplRender(
|
||||
'parts/validation/tests/replace-paths',
|
||||
array(
|
||||
"message" => $this->message,
|
||||
"isOk" => false
|
||||
),
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
|
||||
class DUPX_Validation_test_rest_api extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected $errorMessage = '';
|
||||
protected $restUrl = '';
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
if (true) {
|
||||
// REST API for future feathures
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
$overwriteData = PrmMng::getInstance()->getValue(PrmMng::PARAM_OVERWRITE_SITE_DATA);
|
||||
if (is_array($overwriteData) && isset($overwriteData['restUrl']) && strlen($overwriteData['restUrl']) > 0) {
|
||||
$this->restUrl = $overwriteData['restUrl'];
|
||||
} else {
|
||||
$this->restUrl = PrmMng::getInstance()->getValue(PrmMng::PARAM_URL_NEW) . '/wp-json';
|
||||
}
|
||||
|
||||
|
||||
$this->errorMessage = "REST API call to WordPress backend failed";
|
||||
if (DUPX_REST::getInstance()->checkRest(true, $this->errorMessage)) {
|
||||
return self::LV_PASS;
|
||||
}
|
||||
|
||||
return self::LV_FAIL;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'REST API test';
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender(
|
||||
'parts/validation/tests/rest-api',
|
||||
array(
|
||||
"isOk" => true,
|
||||
"restUrl" => $this->restUrl
|
||||
),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
protected function failContent()
|
||||
{
|
||||
return dupxTplRender(
|
||||
'parts/validation/tests/rest-api',
|
||||
array(
|
||||
"isOk" => false,
|
||||
"errorMessage" => $this->errorMessage,
|
||||
"restUrl" => $this->restUrl
|
||||
),
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
class DUPX_Validation_test_siteground extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected function runTest()
|
||||
{
|
||||
if (!DUPX_Custom_Host_Manager::getInstance()->isHosting(DUPX_Custom_Host_Manager::HOST_SITEGROUND)) {
|
||||
return self::LV_SKIP;
|
||||
}
|
||||
|
||||
return self::LV_SOFT_WARNING;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Siteground';
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/siteground', array(), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
class DUPX_Validation_test_timeout extends DUPX_Validation_abstract_item
|
||||
{
|
||||
const MAX_TIME_SIZE = 314572800; //300MB
|
||||
|
||||
protected $maxTimeZero = false;
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
$max_time_ini = ini_get('max_execution_time');
|
||||
$this->maxTimeZero = ($GLOBALS['DUPX_ENFORCE_PHP_INI']) ? false : @set_time_limit(0);
|
||||
|
||||
if ((is_numeric($max_time_ini) && $max_time_ini < 31 && $max_time_ini > 0) && DUPX_Conf_Utils::archiveSize() > self::MAX_TIME_SIZE) {
|
||||
return self::LV_SOFT_WARNING;
|
||||
} else {
|
||||
return self::LV_GOOD;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'PHP Timeout';
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/timeout', array(
|
||||
'maxTimeZero' => $this->maxTimeZero,
|
||||
'maxTimeIni' => ini_get('max_execution_time'),
|
||||
'archiveSize' => DUPX_U::readableByteSize(DUPX_Conf_Utils::archiveSize()),
|
||||
'maxSize' => DUPX_U::readableByteSize(self::MAX_TIME_SIZE),
|
||||
'isOk' => true
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function goodContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/timeout', array(
|
||||
'maxTimeZero' => $this->maxTimeZero,
|
||||
'maxTimeIni' => ini_get('max_execution_time'),
|
||||
'archiveSize' => DUPX_U::readableByteSize(DUPX_Conf_Utils::archiveSize()),
|
||||
'maxSize' => DUPX_U::readableByteSize(self::MAX_TIME_SIZE),
|
||||
'isOk' => true
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
|
||||
class DUPX_Validation_test_tokenizer extends DUPX_Validation_abstract_item
|
||||
{
|
||||
protected function runTest()
|
||||
{
|
||||
if (function_exists('token_get_all')) {
|
||||
return self::LV_PASS;
|
||||
} else {
|
||||
PrmMng::getInstance()->setValue(PrmMng::PARAM_WP_CONFIG, 'nothing');
|
||||
PrmMng::getInstance()->save();
|
||||
return self::LV_HARD_WARNING;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'PHP Tokenizer';
|
||||
}
|
||||
|
||||
protected function hwarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/tokenizer', array(
|
||||
'isOk' => false
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function passContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/tokenizer', array(
|
||||
'isOk' => true
|
||||
), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validation object
|
||||
*
|
||||
* Standard: PSR-2
|
||||
*
|
||||
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
|
||||
*
|
||||
* @package SC\DUPX\U
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || defined('DUPXABSPATH') || exit;
|
||||
|
||||
use Duplicator\Installer\Utils\Log\LogHandler;
|
||||
use Duplicator\Installer\Core\Params\PrmMng;
|
||||
use Duplicator\Libs\Snap\SnapIO;
|
||||
|
||||
class DUPX_Validation_test_wordfence extends DUPX_Validation_abstract_item
|
||||
{
|
||||
private $wordFencePath = "";
|
||||
|
||||
protected function runTest()
|
||||
{
|
||||
return $this->parentHasWordfence() ? self::LV_HARD_WARNING : self::LV_GOOD;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Wordfence';
|
||||
}
|
||||
|
||||
protected function swarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/wordfence/wordfence-detected', array(
|
||||
'wordFencePath' => $this->wordFencePath
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function hwarnContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/wordfence/wordfence-detected', array(
|
||||
'wordFencePath' => $this->wordFencePath
|
||||
), false);
|
||||
}
|
||||
|
||||
protected function goodContent()
|
||||
{
|
||||
return dupxTplRender('parts/validation/tests/wordfence/wordfence-not-detected', array(), false);
|
||||
}
|
||||
|
||||
protected function parentHasWordfence()
|
||||
{
|
||||
$scanPath = PrmMng::getInstance()->getValue(PrmMng::PARAM_PATH_NEW);
|
||||
$rootPath = SnapIO::getMaxAllowedRootOfPath($scanPath);
|
||||
$result = false;
|
||||
|
||||
if ($rootPath === false) {
|
||||
//$scanPath is not contained in open_basedir paths skip
|
||||
return false;
|
||||
}
|
||||
|
||||
LogHandler::setMode(LogHandler::MODE_OFF);
|
||||
$continueScan = true;
|
||||
while ($continueScan) {
|
||||
if ($this->wordFenceFirewallEnabled($scanPath)) {
|
||||
$this->wordFencePath = $scanPath;
|
||||
$result = true;
|
||||
break;
|
||||
}
|
||||
$continueScan = $scanPath !== $rootPath && $scanPath != dirname($scanPath);
|
||||
$scanPath = dirname($scanPath);
|
||||
}
|
||||
LogHandler::setMode();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function wordFenceFirewallEnabled($path)
|
||||
{
|
||||
$configFiles = array(
|
||||
'php.ini',
|
||||
'.user.ini',
|
||||
'.htaccess'
|
||||
);
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$file = $path . '/' . $configFile;
|
||||
|
||||
if (!@is_readable($file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (($content = @file_get_contents($file)) === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strpos($content, 'wordfence-waf.php') !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user