59 if (($realContextRoot = realpath(
$contextRoot)) ===
false) {
62 $this->contextRoot = $realContextRoot;
72 if (($dh = opendir(
$dir)) ===
false) {
75 while ((
$file = readdir($dh)) !==
false) {
80 if (!is_link($absLink)) {
83 $target = readlink($absLink);
84 if ($target ===
false) {
87 if (substr($target, 0, 1) !=
'/') {
88 $target = dirname($absLink) . DIRECTORY_SEPARATOR . $target;
90 if (file_exists($target)) {
93 $this->
verbose(2, sprintf(
"Deleting link '%s' to non-existing file '%s'.\n", $absLink, $target));
94 if (unlink($absLink) ===
false) {
96 throw new WStartException(sprintf(
"Error deleting dead symlink '%s' to '%s'.", $absLink, $target));
109 public function linkFiles($sourceDir, $destDir, &$linked = array())
111 $this->
verbose(2, sprintf(
"Processing files from '%s'.\n", $sourceDir));
112 if (($dh = opendir($this->
absolutize($sourceDir))) ===
false) {
115 while ((
$file = readdir($dh)) !==
false) {
119 $relSourceFile = $this->
relativize($sourceDir . DIRECTORY_SEPARATOR .
$file);
120 $absSourceFile = $this->
absolutize($relSourceFile);
121 if (!is_file($absSourceFile) && !is_dir($absSourceFile)) {
124 $relTarget =
'..' . DIRECTORY_SEPARATOR . $relSourceFile;
125 $absLink = $this->
absolutize($destDir . DIRECTORY_SEPARATOR . basename($relSourceFile));
126 if (!isset($linked[$absLink])) {
127 $linked[$absLink] = array();
129 if (is_link($absLink)) {
130 $source = readlink($absLink);
131 if ($source !==
false && $source == $relTarget) {
132 $linked[$absLink][] = $relTarget;
135 if (unlink($absLink) ===
false) {
137 throw new WStartException(sprintf(
"Error removing symlink '%s'.", $absLink));
140 $this->
verbose(2, sprintf(
"Linking '%s' to '%s'.\n", $relTarget, $absLink));
141 if (symlink($relTarget, $absLink) ===
false) {
143 throw new WStartException(sprintf(
"Error symlinking '%s' to '%s'.", $relTarget, $absLink));
145 $linked[$absLink][] = $relTarget;
173 if (($dh = opendir(
$dir)) ===
false) {
176 while ((
$file = readdir($dh)) !==
false) {
181 if (
$ret ===
false) {
183 throw new WStartException(sprintf(
"Malformed regex pattern '%s'.", $regex));
188 $this->
verbose(2, sprintf(
"Removing '%s'.\n",
$dir . DIRECTORY_SEPARATOR .
$file));
189 if (unlink(
$dir . DIRECTORY_SEPARATOR . $file) ==
false) {
191 throw new WStartException(sprintf(
"Error removing file '%s'.", $file));
204 $appImagesDirs = array();
205 if (($dh = opendir($this->contextRoot)) ===
false) {
206 return $appImagesDirs;
208 while (($elmt = readdir($dh)) !==
false) {
209 if ($elmt ==
'.' || $elmt ==
'..') {
212 if ($elmt ===
'supervisor') {
218 if (!is_dir($this->
absolutize($elmt . DIRECTORY_SEPARATOR . $subdir))) {
221 $appImagesDirs[] = $elmt . DIRECTORY_SEPARATOR . $subdir;
224 return $appImagesDirs;
236 $this->stdio->wstart_stderr($msg);
249 if ($level <= $this->
verbose) {
250 $this->stdio->wstart_stdout($msg);
270 if (!is_a(
$stdio,
'\Dcp\Utils\WStartStdioInterface')) {
288 if (substr(
$file, 0, 1) !=
'/') {
289 $file = $this->contextRoot . DIRECTORY_SEPARATOR .
$file;
307 if (substr(
$file, 0, 1) !=
'/') {
310 if (
$file == $this->contextRoot) {
313 if (strpos(
$file, $this->contextRoot . DIRECTORY_SEPARATOR) === 0) {
314 $file = substr(
$file, strlen($this->contextRoot . DIRECTORY_SEPARATOR));
320 throw new WStartException(sprintf(
"Could not relativize '%s' to '%s'.",
$file, $this->contextRoot));
329 if (($perms = fileperms(
$file)) ===
false) {
332 $content = file_get_contents(
$file);
333 if ($content ===
false) {
336 $content = call_user_func_array($callback, array(
339 $tmpFile = tempnam(
getTmpDir() ,
'sedFile');
340 if ($tmpFile ===
false) {
343 if (file_put_contents($tmpFile, $content) ===
false) {
345 throw new WStartException(sprintf(
"Error writing content to temporary file '%s'.", $tmpFile));
347 if (rename($tmpFile,
$file) ===
false) {
352 $perms = $perms & 07777;
353 if (chmod(
$file, $perms) ===
false) {
366 $this->
verbose(1, sprintf(
"[+] Re-generating class autoloader.\n"));
367 require_once sprintf(
'%s/WHAT/classAutoloader.php', $this->contextRoot);
369 $this->
verbose(1, sprintf(
"[+] Done.\n"));
376 $this->
verbose(1, sprintf(
"[+] Re-generating Images and Docs symlinks.\n"));
380 $this->
mkdir($imagesDir);
382 foreach ($dirs as
$dir) {
383 $this->
linkFiles($dir, $imagesDir, $linked);
388 $this->
mkdir($docsDir);
390 foreach ($dirs as $dir) {
391 $this->
linkFiles($dir, $this->contextRoot . DIRECTORY_SEPARATOR .
'Docs', $linked);
395 foreach ($linked as $link => $targetList) {
396 if (count($targetList) <= 1) {
399 $targets = join(
', ', $targetList);
400 $this->
debug(sprintf(
"WARNING: symlink '%s' has multiple targets: %s\n", $link, $targets));
402 $this->
verbose(1, sprintf(
"[+] Done.\n"));
409 $this->
verbose(1, sprintf(
"[+] Clearing cached content.\n"));
410 $cacheDir = $this->
absolutize(
'var' . DIRECTORY_SEPARATOR .
'cache' . DIRECTORY_SEPARATOR .
'image');
412 $this->
verbose(1, sprintf(
"[+] Done.\n"));
419 $this->
verbose(1, sprintf(
"[+] Incrementing WVERSION.\n"));
420 $cmd = sprintf(
"%s/wsh.php --api=refreshjsversion 2>&1", escapeshellarg($this->contextRoot));
423 $this->
debug(join(
"\n", $output) .
"\n");
426 $this->
verbose(1, sprintf(
"[+] Done.\n"));
433 $this->
verbose(1, sprintf(
"[+] Configuring CORE_DBCONNECT.\n"));
434 require_once sprintf(
'%s/WHAT/Lib.Common.php', $this->contextRoot);
435 $CORE_DBCONNECT =
getParam(
'CORE_DBCONNECT');
436 if ($CORE_DBCONNECT ==
'persistent') {
439 return preg_replace(
'/\bpg_connect\b/',
'pg_pconnect', $content);
444 return preg_replace(
'/\bpg_pconnect\b/',
'pg_connect', $content);
447 $this->
verbose(1, sprintf(
"[+] Done.\n"));
454 $this->
verbose(1, sprintf(
"[+] Recomputing style assets.\n"));
455 $cmd = sprintf(
"%s/wsh.php --api=setStyle 2>&1", escapeshellarg($this->contextRoot));
458 $this->
debug(join(
"\n", $output) .
"\n");
461 $this->
verbose(1, sprintf(
"[+] Done.\n"));
468 $this->
verbose(1, sprintf(
"[+] Removing maintenance mode.\n"));
469 $maintenanceFile = $this->
absolutize(
'maintenance.lock');
470 if (is_file($maintenanceFile)) {
471 if (unlink($maintenanceFile) ===
false) {
472 throw new WStartException(sprintf(
"Error removing file '%s'.", $maintenanceFile));
475 $this->
verbose(1, sprintf(
"[+] Done.\n"));
483 require_once
'WHAT/Lib.Common.php';
484 require_once
'WHAT/autoload.php';
486 $this->
verbose(1, sprintf(
"[+] Reapplying database parameters.\n"));
487 if ((
$err =
simpleQuery(
'',
'SELECT current_database()', $dbName,
true,
true,
false)) !==
'') {
491 'DateStyle' =>
'ISO, DMY',
492 'standard_conforming_strings' =>
'off'
494 foreach ($paramList as $paramName => $paramValue) {
495 $sql = sprintf(
"ALTER DATABASE %s SET %s = %s", pg_escape_identifier($dbName) , pg_escape_identifier($paramName) , pg_escape_literal($paramValue));
497 throw new WStartException(sprintf(
"Error setting '%s' = '%s' on database '%s': %s", $paramName, $paramValue, $dbName,
$err));
500 $this->
verbose(1, sprintf(
"[+] Done.\n"));
Exception class use exceptionCode to identifiy correctly exception.
setContextRoot($contextRoot)
reapplyDatabaseParameters()
foreach($argv as $arg) $cmd
__construct($contextRoot)
linkFiles($sourceDir, $destDir, &$linked=array())
getParam($name, $def="")
must be in core or global type
removeFilesByRegex($dir, $regex)
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
if($file) if($subject==""&&$file) if($subject=="") $err
sedFile($file, $callback)