Validate the database is ready for installation process
@return boolean|string
489216
public function validateDb()
    {
        $existing = $this->db->query('SHOW TABLES')->fetchColumn();

        if (empty($existing)) {
            return true;
        }

        return $this->translation->text('The database you specified already has tables');
    }
1303080
protected function validService()
	{
		//check if the service variable is empty
		$empty  = empty($this->service);

		//check if this service is an instance if MySQL
		$instance = $this->service instanceof \MySQLi;

		//return true if there is a valid connection and $this->service is an instance of MySQLi
		if ($this->connected && $instance && ! $empty) 
		{
			//return true in this case
			return true;

		}

		//otherwise return false
		return false;

	}
1031699
protected function validateInputDbTypeInstall()
    {
        $drivers = PDO::getAvailableDrivers();
        $title = $this->text('Database type (enter a number)');
        $input = $this->menu(array_combine($drivers, $drivers), 'mysql', $title);

        if (!$this->isValidInput($input, 'database.type', 'install')) {
            $this->errors();
            $this->validateInputDbTypeInstall();
        }
    }
768687
protected function validateDbTypeInstall()
    {
        $field = 'database.type';

        if ($this->isExcluded($field)) {
            return null;
        }

        $value = $this->getSubmitted($field);

        if (empty($value)) {
            $this->setErrorRequired($field, $this->translation->text('Database type'));
            return false;
        }

        $drivers = \PDO::getAvailableDrivers();

        if (in_array($value, $drivers)) {
            return true;
        }

        $error = $this->translation->text('Unsupported database driver. Available drivers: @list', array(
            '@list' => implode(',', $drivers)));

        $this->setError($field, $error);
        return false;
    }
1014594
public function performCheck()
    {
        try {
            $supported = false;
            foreach ($this->connection->fetchAll('show engines') as $engine) {
                $engine = array_change_key_case($engine, CASE_LOWER);
                if (isset($engine['engine']) && strtolower($engine['engine']) == 'innodb') {
                    $supported = true;
                    break;
                }
            }
            if ($supported) {
                $result = new PreconditionResult(PreconditionResult::STATE_PASSED);
            } else {
                $result = new PreconditionResult(PreconditionResult::STATE_FAILED, t('Your MySQL database does not support InnoDB database tables. These are required.'));
            }
        } catch (Exception $x) {
            $result = new PreconditionResult(PreconditionResult::STATE_FAILED, $x->getMessage());
        }

        return $result;
    }
289212
public function check()
    {
        // Check for a title.
        if (trim($this->title) == '')
        {
            $this->setError(JText::_('JLIB_DATABASE_ERROR_MUSTCONTAIN_A_TITLE_CATEGORY'));

            return false;
        }

        $this->alias = trim($this->alias);

        if (empty($this->alias))
        {
            $this->alias = $this->title;
        }

        $this->alias = JApplicationHelper::stringURLSafe($this->alias, $this->language);

        if (trim(str_replace('-', '', $this->alias)) == '')
        {
            $this->alias = JFactory::getDate()->format('Y-m-d-H-i-s');
        }

        return true;
    }
492404
public function is_ready() {
        if (empty($this->pathtopython)) {
            $settingurl = new \moodle_url('/admin/settings.php', array('section' => 'systempaths'));
            return get_string('pythonpathnotdefined', 'mlbackend_python', $settingurl->out());
        }

        // Check the installed pip package version.
        $cmd = "{$this->pathtopython} -m moodlemlbackend.version";

        $output = null;
        $exitcode = null;
        // Execute it sending the standard error to $output.
        $result = exec($cmd . ' 2>&1', $output, $exitcode);

        $vercheck = self::check_pip_package_version($result);

        if ($vercheck === 0) {
            return true;
        }

        if ($exitcode != 0) {
            return get_string('pythonpackagenotinstalled', 'mlbackend_python', $cmd);
        }

        if ($result) {
            $a = [
                'installed' => $result,
                'required' => self::REQUIRED_PIP_PACKAGE_VERSION,
            ];

            if ($vercheck < 0) {
                return get_string('packageinstalledshouldbe', 'mlbackend_python', $a);

            } else if ($vercheck > 0) {
                return get_string('packageinstalledtoohigh', 'mlbackend_python', $a);
            }
        }

        return get_string('pythonpackagenotinstalled', 'mlbackend_python', $cmd);
    }
1211267
public function validateCurrentInstall() {
		if (!file_exists($this->installStatusFile)) {
			throw new MoufException("No install status file found. I don't know what install task should be run.");
		}
		
		$statusArray = json_decode(file_get_contents($this->installStatusFile), true);
		if ($statusArray['type'] == 'one') {
			$taskArray = $statusArray['task'];
			// Now, let's find the matching task and mark it "done".
			$installTask = $this->findInstallTaskFromArray($taskArray);
			$installTask->setStatus(AbstractInstallTask::STATUS_DONE);
			$this->save();
			
			// Finally, let's delete the install status file.
			unlink($this->installStatusFile);
		} else {
			$installTasks = $this->getInstallTasks();
			foreach ($installTasks as $installTask) {
				if ($installTask->getStatus() == AbstractInstallTask::STATUS_TODO) {
					$installTask->setStatus(AbstractInstallTask::STATUS_DONE);
					$this->save();
					break;
				}
			}
			$todoRemaining = false;
			foreach ($installTasks as $installTask) {
				if ($installTask->getStatus() == AbstractInstallTask::STATUS_TODO) {
					$todoRemaining = true;
					break;
				}
			}
			if (!$todoRemaining) {
				// Finally, let's delete the install status file if there are no actions in "todo" state
				unlink($this->installStatusFile);
			}
		}
		
	}
1090235
protected function validateWizardInstall()
    {
        $this->selectLanguage();
        $this->validateRequirementsInstall();
        $this->validateInstallerInstall();

        $this->validatePrompt('store.title', $this->text('Store title'), 'install', 'GPLCart');
        $this->validatePrompt('user.email', $this->text('E-mail'), 'install');
        $this->validatePrompt('user.password', $this->text('Password'), 'install');
        $this->validatePrompt('store.host', $this->text('Host'), 'install', 'localhost');
        $this->validatePrompt('store.basepath', $this->text('Installation subdirectory'), 'install', '');

        $this->validateInputDbInstall();
        $this->validateInputInstall();
    }
732812
protected function _check() {
		$result = true;
		$this->out(__d('cake_installer', 'Checking PHP version'));
		$this->hr();
		$phpVesion = $this->InstallerCheck->checkPHPversion();
		if ($phpVesion !== null) {
			if ($phpVesion) {
				$state = '<success>' . __d('cake_installer', 'Ok') . '</success>';
			} else {
				$state = '<error>' . __d('cake_installer', 'Bad') . '</error>';
				$result = false;
			}
			$state = '[' . $state . ']';

			$message = ' * ' . __d('cake_installer', 'Current PHP version: %s', PHP_VERSION);
			$formattedMessage = $this->state->getState($message, $state, $this->maxWidth - 1);
		} else {
			$formattedMessage = __d('cake_installer', 'Ok');
		}
		$this->out($formattedMessage, 1);
		$this->hr();
		$this->nl(1);

		$this->out(__d('cake_installer', 'Checking PHP extensions'));
		$this->hr();
		$phpModules = $this->InstallerCheck->checkPhpExtensions();
		if ($phpModules !== null) {
			$result = true;
			$messages = [];
			$this->waiting->animateMessage();
			foreach ($phpModules as $moduleName => $moduleState) {
				switch ($moduleState) {
					case 2:
						$state = '<success>' . __d('cake_installer', 'Ok') . '</success>';
						break;
					case 1:
						$state = '<warning>' . __d('cake_installer', 'Ok') . '</warning>';
						break;
					default:
						$state = '<error>' . __d('cake_installer', 'Bad') . '</error>';
						$result = false;
				}
				$state = '[' . $state . ']';
				$message = ' * ' . __d('cake_installer', 'Checking module is loaded: \'%s\'', $moduleName);
				$messages[] = $this->state->getState($message, $state, $this->maxWidth - 1);
				$this->waiting->animateMessage();
			}
			$this->waiting->hideMessage();
		} else {
			$messages = __d('cake_installer', 'Ok');
		}
		$this->out($messages, 1);
		$this->hr();
		$this->nl(1);
		if ($result) {
			$this->out('<success>' . __d('cake_installer', 'Check completed successfully.') . '</success>');
		} else {
			$this->out('<error>' . __d('cake_installer', 'Check completed unsuccessfully.') . '</error>');
		}

		return $result;
	}
1240710
public function validateDate()
    {
        if (
            ($from = $this->getAvailableFrom()) &&
            ($till = $this->getAvailableTill()) &&
            $from->InPast() &&
            $till->InFuture()
        ) {
            return true;
        }

        return false;
    }
438717
protected static function databaseIsReady()
    {
        $object = DataObject::singleton(static::class);

        // if any of the tables aren't created in the database
        $table = $object->baseTable();
        if (!ClassInfo::hasTable($table)) {
            return false;
        }

        // if any of the tables don't have all fields mapped as table columns
        $dbFields = DB::field_list($table);
        if (!$dbFields) {
            return false;
        }

        $objFields = $object->getSchema()->databaseFields($object, false);
        $missingFields = array_diff_key($objFields, $dbFields);

        if ($missingFields) {
            return false;
        }

        return true;
    }
741277
public function check(): bool
    {
        try {
            DB::connection()->getPdo();
        } catch (PDOException $e) {
            $this->error = $e->getMessage();

            return false;
        }

        return true;
    }
975841
public function valid()
    {
        if($this->folderList == null){
            $this->folderList = $this->listFolder();
        }
        return is_array($this->folderList) && isset($this->folderList[$this->key]);
    }
1201481
public function valid()
    {
        $encryptStr = "";
        if ($_SERVER['REQUEST_METHOD'] == "POST") {
            $postStr = file_get_contents("php://input");
            $disableEntities = libxml_disable_entity_loader(true);
            $array = (array)simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
            libxml_disable_entity_loader($disableEntities);
            $this->encrypt_type = isset($_GET["encrypt_type"]) ? $_GET["encrypt_type"] : '';
            if ($this->encrypt_type == 'aes') {
                $encryptStr = $array['Encrypt'];
                !class_exists('Prpcrypt', false) && require __DIR__ . '/Prpcrypt.php';
                $pc = new Prpcrypt($this->encodingAesKey);
                $array = $pc->decrypt($encryptStr, $this->appid);
                if (!isset($array[0]) || intval($array[0]) > 0) {
                    $this->errCode = $array[0];
                    $this->errMsg = $array[1];
                    Tools::log("Interface Authentication Failed. {$this->errMsg}[{$this->errCode}]", "ERR - {$this->appid}");
                    return false;
                }
                $this->postxml = $array[1];
                empty($this->appid) && $this->appid = $array[2];
            } else {
                $this->postxml = $postStr;
            }
        } elseif (isset($_GET["echostr"])) {
            if ($this->checkSignature()) {
                @ob_clean();
                exit($_GET["echostr"]);
            }
            return false;
        }
        if (!$this->checkSignature($encryptStr)) {
            $this->errMsg = 'Interface authentication failed, please use the correct method to call.';
            return false;
        }
        return true;
    }
1243908
public function isValid()
    {
        $isOk = $this->error === UPLOAD_ERR_OK;

        return $this->test ? $isOk : $isOk && is_uploaded_file($this->getPathname());
    }
1239984
public function validateReceived()
    {
        $this->debugMessage[] = 'IPN VALIDATION: START';
        if (!$this->ipnPostDataCheck()) {
            $this->debugMessage[] = 'IPN VALIDATION: END';
            return false;
        }

        //'ORDERSTATUS'
        $this->logFunc("IPN", $this->postData, @$this->postData['REFNOEXT']);
        if (!in_array(trim($this->postData['ORDERSTATUS']), $this->successfulStatus)) {
            $this->errorMessage[] = 'INVALID IPN ORDER STATUS: ' . $this->postData['ORDERSTATUS'];
            $this->debugMessage[] = 'IPN VALIDATION: END';
            return false;
        }
        $validationResult = false;
        $calculatedHashString = $this->createHashString($this->flatArray($this->postData, array("HASH")));
        if ($calculatedHashString == $this->postData['HASH']) {
            $validationResult = true;
        }
        if ($validationResult) {
            $this->debugMessage[] = 'IPN VALIDATION: ' . 'SUCCESSFUL';
            $this->debugMessage[] = 'IPN CALCULATED HASH: ' . $calculatedHashString;
            $this->debugMessage[] = 'IPN HASH: ' . $this->postData['HASH'];
            $this->debugMessage[] = 'IPN VALIDATION: END';
            return true;
        } elseif (!$validationResult) {
            $this->errorMessage[] = 'IPN VALIDATION: ' . 'FAILED';
            $this->errorMessage[] = 'IPN CALCULATED HASH: ' . $calculatedHashString;
            $this->errorMessage[] = 'IPN RECEIVED HASH: ' . $this->postData['HASH'];
            $this->debugMessage[] = 'IPN VALIDATION: END';
            return false;
        }
        return false;
    }