protected function setupDist()

in pgo/cases/joomla/TrainingCaseHandler.php [48:100]


	protected function setupDist() : void
	{
		$port = $this->getHttpPort();
		$host = $this->getHttpHost();
		$db_port = $this->getDbPort();
		$db_host = $this->getDbHost();
		$db_user = $this->getDbUser();
		$db_pass = $this->getDbPass();

		$vars = array(
			$this->conf->buildTplVarName($this->getName(), "docroot") => str_replace("\\", "/", $this->base),
		);
		$tpl_fn = $this->conf->getCasesTplDir($this->getName()) . DIRECTORY_SEPARATOR . "nginx.partial.conf";
		$this->nginx->addServer($tpl_fn, $vars);

		$php = new PHP\CLI($this->conf);

		$this->maria->up();
		$this->nginx->up();

		$this->maria->query("DROP DATABASE IF EXISTS " . $this->getName());
		$this->maria->query("CREATE DATABASE " . $this->getName() . " CHARACTER SET utf8");

		$htdocs = $this->conf->getCaseWorkDir($this->getName());
		if (is_dir($htdocs . DIRECTORY_SEPARATOR . "_installation")) {
			rename($htdocs . DIRECTORY_SEPARATOR . "_installation", $htdocs . DIRECTORY_SEPARATOR . "installation");
		}

		$env = array(
			"PATH" => $this->conf->getSrvDir(strtolower($this->maria->getName())) . DIRECTORY_SEPARATOR . "bin",
		);

		$www = $this->conf->getCaseWorkDir();
		$login = $db_pass ? "$db_user:$db_pass" : $db_user;
		$cmd = $this->getToolFn() . " site:install --overwrite --sample-data=learn --mysql-database=" . $this->getName() . " --mysql-login=$login --mysql-host=$db_host --mysql-port=$db_port --www=$www " . $this->getName();
		//$cmd = $this->getToolFn() . " site:install --drop --overwrite --sample-data=default --mysql-database=" . $this->getName() . " --mysql-login=$login --mysql-host=$db_host --mysql-port=$db_port --www=$www " . $this->getName();
		//$cmd = $this->getToolFn() . " site:create --clear-cache --disable-ssl --release=3.7 --http-port=$port --sample-data=testing --mysql-database=" . $this->getName() . " --mysql-login=$login --mysql-host=$db_host --mysql-port=$db_port --www=$www " . $this->getName();
		$php->exec($cmd, NULL, $env);

		if (is_dir($htdocs . DIRECTORY_SEPARATOR . "installation")) {
			rename($htdocs . DIRECTORY_SEPARATOR . "installation", $htdocs . DIRECTORY_SEPARATOR . "_installation");
		}

		$fn = $htdocs . DIRECTORY_SEPARATOR . "configuration.php";
		$s = file_get_contents($fn);
		$s = str_replace("public \$debug = '1';", "public \$debug = '0';", $s);
		if (strlen($s) !== file_put_contents($fn, $s)) {
			throw new Exception("Couldn't write '$fn'.");
		}

		$this->nginx->down(true);
		$this->maria->down(true);
	}