public static function redirectViewRecord(ActiveRecord $Record, $path = array(), $permanent = false)
 {
     if (is_array($path)) {
         $path = implode('/', $path);
     }
     if (!($url = $Record->getURL())) {
         if (!($classPath = static::getClassPath($Record))) {
             return RequestHandler::throwError('No route to record viewer');
         }
         $url = '/' . $classPath . '/' . $Record->getHandle();
     }
     if ($path) {
         $url .= '/' . ltrim($path, '/');
     }
     if ($permanent) {
         Site::redirectPermanent($url);
     } else {
         Site::redirect($url);
     }
 }
<?php

$GLOBALS['Session']->requireAccountLevel('Developer');
set_time_limit(0);
RequestHandler::$responseMode = 'json';
if (empty($_REQUEST['path'])) {
    RequestHandler::throwError('path required');
}
if (empty($_REQUEST['host'])) {
    RequestHandler::throwError('host required');
}
if (!($sourceCollection = Site::resolvePath($_REQUEST['path']))) {
    RequestHandler::throwError('path not found locally');
}
// create stream context for remote server
$syncer = new EmergenceSyncer(array('host' => $_REQUEST['host'], 'authUsername' => $_SERVER['PHP_AUTH_USER'], 'authPassword' => $_SERVER['PHP_AUTH_PW']));
$diff = $syncer->diffCollection($sourceCollection, !empty($_REQUEST['deep']));
if (empty($_REQUEST['push'])) {
    RequestHandler::respond('diff', array('diff' => $diff));
} else {
    $result = $syncer->pushDiff($diff);
    RequestHandler::respond('pushComplete', array('result' => $result));
}