/** * Removes orphaned lock files - by checking their PIDs against running processes * @param array $opts */ public static function cleanup($opts = array()) { if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { exec('tasklist /FO CSV', $runningProcesses, $return_var); $runningProcesses = array_map(function ($line) { $cols = explode(',', $line); return trim($cols[1], '"'); }, $runningProcesses); unset($runningProcesses[0]); // 'PID' sort($runningProcesses); unset($runningProcesses[0]); // 0 } else { exec('ps -e -o pid', $runningProcesses, $return_var); } if ($return_var != 0) { pake_echo_error("Could not get list of processes to remove stale lock files"); return; } $lockDir = self::lockDir($opts); foreach (glob($lockDir . "/*_W.lock") as $writeLock) { $pid = file_get_contents($writeLock); //strstr( file_get_contents( $writeLock ), ' ', true ); if (!in_array($pid, $runningProcesses)) { pake_unlink($writeLock); } } foreach (glob($lockDir . "/*_R/*.lock") as $readLock) { $pid = file_get_contents($readLock); // strstr( file_get_contents( $readLock ), ' ', true ); if (!in_array($pid, $runningProcesses)) { pake_unlink($readLock); } } }
/** * Removes directory and all it's contents * * @param $path string */ function pake_remove_dir($path) { if (!file_exists($path)) { // nothing to do return; } if (!is_dir($path)) { throw new pakeException('"' . $path . '" is not a directory'); } // remove contents $finder = pakeFinder::type('any'); pake_remove($finder, $path); // remove folder pake_unlink($path); }
/** * Updates the "eZ CP version history" document, currently hosted on pubsvn.ez.no. * * Options: --public-keyfile=<...> --private-keyfile=<...> --user=<...> --private-keypasswd=<...> * * @todo add support for getting ssl certs options in config settings */ public static function run_update_version_history($task = null, $args = array(), $cliopts = array()) { $opts = self::getOpts($args, $cliopts); $public_keyfile = @$cliopts['public-keyfile']; $private_keyfile = @$cliopts['private-keyfile']; $private_keypasswd = @$cliopts['private-keypasswd']; $user = @$cliopts['user']; // get file $srv = "http://pubsvn.ez.no"; $filename = "/ezpublish_version_history/ez_history.csv"; $fullfilename = $srv . $filename; $remotefilename = '/mnt/pubsvn.ez.no/www/' . $filename; $file = pake_read_file($fullfilename); if ("" == $file) { throw new pakeException("Couldn't download {$fullfilename} file"); } // patch it /// @todo test that what we got looks at least a bit like what we expect $lines = preg_split("/\r?\n/", $file); $lines[0] .= $opts['version']['alias'] . ','; $lines[1] .= strftime('%Y/%m/%d') . ','; $file = implode("\n", $lines); /// @todo: back up the original as well (upload 1st to srv the unpatched version with a different name, then the new version) // upload it: we use curl for sftp $randfile = tempnam(sys_get_temp_dir(), 'EZP'); pake_write_file($randfile, $file, true); $fp = fopen($randfile, 'rb'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, str_replace('http://', 'sftp://@', $srv) . $remotefilename); if ($user != "") { curl_setopt($ch, CURLOPT_USERPWD, $user); } if ($public_keyfile != "") { curl_setopt($ch, CURLOPT_SSH_PUBLIC_KEYFILE, $public_keyfile); } if ($private_keyfile != "") { curl_setopt($ch, CURLOPT_SSH_PRIVATE_KEYFILE, $private_keyfile); } if ($private_keypasswd != "") { curl_setopt($ch, CURLOPT_KEYPASSWD, $private_keypasswd); } curl_setopt($ch, CURLOPT_UPLOAD, 1); curl_setopt($ch, CURLOPT_INFILE, $fp); // set size of the file, which isn't _mandatory_ but helps libcurl to do // extra error checking on the upload. curl_setopt($ch, CURLOPT_INFILESIZE, filesize($randfile)); $ok = curl_exec($ch); $errinfo = curl_error($ch); curl_close($ch); fclose($fp); pake_unlink($randfile); if (!$ok) { throw new pakeException("Couldn't write {$fullfilename} file: " . $errinfo); } pake_echo_action("file+", $filename); }