Exemplo n.º 1
0
function main() {
    global $path_prefix;

    ?>

<h1>PeopleAggregator system update</h1>

<p>system update | <a href="version.php">version info</a></p>

    <?
        
    $tmp_dir = "$path_prefix/web/files";
    $tmp_fn = "$tmp_dir/update.treediff.xml";

    $state = new Subversion_PAStateStore($path_prefix);

    if (!$state->is_initialized()) $state->initialize();
    $client = new Subversion_StandaloneClient($state, $tmp_fn);
    
    $op = @$_POST['op'];
    switch ($op) {
    case 'login':
	break;
	
    case 'download':
	echo "<h2>downloading update</h2>";

        $root = $state->get_repository_root();

        if (preg_match("|^https://|", $root)) {
            echo "<p>ERROR: attempting to update from an HTTPS update server (<code>$root</code>), but we can't do HTTPS :-(</p>";
            break;
        }

        if (!preg_match("|^http://update.peopleaggregator.org/svn|", $root)) {
            echo '<p>WARNING: the update server is <code>'.$root.'</code>, which is not the official PeopleAggregator update server.</p>';
        }
        elseif ($root != 'http://update.peopleaggregator.org/svn/release') {
            echo '<p>WARNING: updating from '.$root.', which is on the official PeopleAggregator server, but may be a test release.</p>';
        }

	$rev = $state->get_revision();
	echo '<p>Requesting an update from revision r'.$rev.' from the server (<a href="'.$root.'">root</a>, <a href="'.$root.$state->get_repository_path().'">path</a>).</p>';
	
	$disp = new js_display();
	$disp->start();
	$client->displayer = $disp;
	$client->checkout();

        $err = NULL;
	$f = @fopen($tmp_fn, "rt");
	if ($f) {
            $xml = fread($f, 8192);
            fclose($f);
            if (!preg_match("|^<"."\?xml|", $xml)) {
                $err = "Invalid response received.";
            }
            else if (preg_match("|<m:human-readable.*?>(.*?)</m:human-readable>|s", $xml, $m)) {
                $err = $m[1];
            }
            else if (preg_match('|target-revision rev="(\d+)"|s', $xml, $m)) {
                $target_rev = (int)$m[1];
                if ($target_rev == $rev) {
                    echo "Your system is already up to date.";
                    unlink($tmp_fn);
                }
            }
	} else {
            $err = "Error reading temporary tree diff file $tmp_fn";
        }

        if ($err) {
            echo '<div class="error">An error occurred: <b>'.htmlspecialchars($err).'</b></div>';
            return;
        }

/*<?xml version="1.0" encoding="utf-8"?>
<D:error xmlns:D="DAV:" xmlns:m="http://apache.org/dav/xmlns" xmlns:C="svn:">
<C:error/>
<m:human-readable errcode="160005">
Cannot replace a directory from within
</m:human-readable>
</D:error>*/

	break;
	
    case 'test-apply':
        if (!file_exists($tmp_fn)) break;
    
	echo '<div id="progress-detail"><h2>Verifying that the update can be installed.</h2>'; flush();

	$msg_headers = array(
            "localmod" => "Your local modifications conflict with the update",
            "perms" => "The updater is unable to access some files or directories",
            );

	$client->displayer = new html_display();
	$msg_html = "";
	try {
	    $r = $client->apply_patch(FALSE);
	    $errors = $r['errors'];
            foreach ($errors as $level => $msgs) {
                $msg_list = "";
                foreach ($msgs as $msg) {
                    $msg_list .= "<li>".$msg."</li>";
                }
                $msg_html .= "<h3>".$msg_headers[$level]."</h3>
<ul>$msg_list</ul>";
            }
	} catch (Subversion_Failure $e) {
	    $msg_html = $e->getMessage();
	}

	echo <<<EOF
</div><!-- progress-detail -->
<script language="javascript" type="text/javascript"><!--
  // hide detail, so the user can see the error message
  document.getElementById("progress-detail").style.display = "none";
// --></script>
EOF;

	if ($msg_html) {
	    ?>

<p>The update (from r<?= $state->get_revision() ?> to r<?= $client->target_revision ?>) cannot be installed cleanly for the following reason(s):</p>

<div class="error"><?= $msg_html ?></div>

<p>You have several options at this point if you wish to install the update:</p>

<ol>

 <li>
  <p>Fix the issues listed above, then try installing the update again.</p>
  <? if (!@$errors['localmod']) { ?><p>HIGHLY RECOMMENDED - as the only issues above are to do with file access permissions.  Please fix the permissions, and try again.</p><? } ?>
  <? show_op("test-apply", "Click here to try installing the update again"); ?>
 </li>

 <? if (@$errors['localmod']) { ?>
 <li>
  <p>[NOT IMPLEMENTED YET] Migrate to using Subversion for updates.</p>
  <p>HIGHLY RECOMMENDED if you plan to maintain local changes.</p>
  <? show_op("svn-migrate", "Click here to create .svn folders in your PeopleAggregator install so you can use 'svn update'", TRUE); ?>
 </li>
 <? } ?>

 <li>
  <p>Overwrite your local changes.  This will probably result in a working system, but will destroy any changes you have made to your system, so make sure you know what you are doing!</p>
  <p>(Files with local modifications will be renamed, e.g. changedfile.php will become changedfile.php.local)</p>
  <? if (!@$errors['localmod']) { ?><p>NOT RECOMMENDED - as the only issues above are to do with file access permissions.  Instead, please fix the permissions, and try again.</p><? } ?>
  <? if (@$errors['perms']) { ?><p style="font-weight: bold">CURRENTLY NOT POSSIBLE due to the access permissions errors mentioned above.  Please fix them, then try again.</p><? } ?>
  <? show_op("force-apply", "Click here to install the update, overwriting your local changes.", @$errors['perms'] ? TRUE : FALSE); ?>
 </li>

 <li>
  <p>Install only the parts of the update that do not conflict with anything on your system.</p>
  <p>(Files with local modifications will not be touched, and new local files will block installation of new files or directories of the same name).</p>
  <p>This won't destroy anything you have changed, but could quite possibly result in a broken installation, so it is not recommended unless your changes are relatively minor.</p>
  <? if (!@$errors['localmod']) { ?><p>NOT RECOMMENDED - as the only issues above are to do with file access permissions.  Instead, please fix the permissions, and try again.</p><? } ?>
  <? show_op("soft-apply", "Click here to install the update without overwriting/deleting anything with local changes."); ?>
 </li>

</ol>

            <?
        } else {
	    show_op("apply", "Confirm - apply update to your installation");
	}
	return; // don't show 'an update has been downloaded' text

    case 'apply':
        if (!file_exists($tmp_fn)) break;
	echo "<h2>Applying update.</h2>";
	$client->displayer = new html_display();
	$client->apply_patch(TRUE);
        run_scripts();
	return;

    case 'soft-apply':
        if (!file_exists($tmp_fn)) break;
	echo "<h2>Applying update without overwriting local changes.</h2>";
	$client->displayer = new html_display();
	$client->apply_patch("soft");
        run_scripts();
	return;

    case 'force-apply':
        if (!file_exists($tmp_fn)) break;
	echo "<h2>Apply update, overwriting local changes.</h2>";
        echo "<p>Downloading extra files from the server ...</p><ul>";
        // find files to download
        $client->displayer = new null_display();
        $client->apply_patch();
	$client->displayer = new html_display();
        $client->download_incomplete_files($tmp_dir);
        echo "</ul>";

        // all done - now apply the patch
	$client->apply_patch("force");
        run_scripts();
	return;
	
    default:
	if ($op) throw new Subversion_Failure("Invalid operation: $op");
	break;
    }
    
    if (file_exists($tmp_fn)) {
	show_op("test-apply", "An update has been downloaded.  Click here to apply it to your system.");
    }
    else {
	show_op("download", "Check for updates");
    }
}
Exemplo n.º 2
0
<p>This is the development Subversion repository and revision used to build this release.</p>

<?php 
    $text = file_get_contents("../../db/source_svn_info.txt");
    if (preg_match("/\nURL: (.*?)\n/", $text, $m)) {
        echo "<p>Repository: <code><b>" . htmlspecialchars($m[1]) . "</b></code></p>";
    }
    if (preg_match("/\nRevision: (.*?)\n/", $text, $m)) {
        echo "<p>Revision: <b>" . htmlspecialchars($m[1]) . "</b></p>";
    }
}
?>
<h3>Built-in update system</h3>
<?php 
if ($state->is_initialized()) {
    ?>
 <p>This is the version information used by the built-in update system.  If you have <a href="http://wiki.peopleaggregator.org/Transitioning_to_Subversion_for_updates">transitioned to Subversion</a>, this information will be out of date and your version information will be down below under the "Subversion" heading.</p>
<?php 
    echo "<p>Repository: <code><b>" . htmlspecialchars($state->get_repository_root() . $state->get_repository_path()) . "</b></code></p>";
    echo "<p>Revision: <b>" . htmlspecialchars($state->get_revision()) . "</b></p>";
} else {
    echo "<p>The built-in update system has not been initialized.</p>";
}
?>
<h3>Subversion (external - .svn directory)</h3>
<?php 
// check for .svn/entries
if (file_exists("../../.svn/entries")) {
    echo "<p><code>.svn/entries</code> file found</p>";
    $dom = new DOMDocument();