public static function cacheTree($path, $force = false)
 {
     // split path into array
     if (is_string($path)) {
         $path = Site::splitPath($path);
     }
     // check if this tree has already been cached
     $cacheKey = 'cacheTree:' . implode('/', $path);
     if (!Site::$autoPull || !$force && Cache::fetch($cacheKey)) {
         return 0;
     }
     Cache::store($cacheKey, true);
     // get tree map from parent
     $remoteTree = Emergence::resolveCollectionFromParent($path);
     if (!$remoteTree) {
         return 0;
     }
     $filesResolved = 0;
     $startTime = time();
     foreach ($remoteTree['files'] as $remotePath => $remoteFile) {
         $node = Site::resolvePath($remotePath);
         if ($node && $node->Timestamp >= $startTime) {
             $filesResolved++;
         }
     }
     return $filesResolved;
 }
 public static function getByEmergenceVFS($path)
 {
     $vfsPath = static::get_virtual_path(str_replace('vfs://', '', $path));
     $templateNode = false;
     $streamPath = Site::splitPath($vfsPath);
     if (!empty($streamPath[0])) {
         $topFolder = array_shift($streamPath);
         $localRoot = Site::getRootCollection($topFolder);
         $searchStack = array_filter($streamPath);
         while (true) {
             $searchPath = $searchStack;
             if ($templateNode = $localRoot->resolvePath($searchPath)) {
                 break;
             }
             if ($templateNode = Emergence::resolveFileFromParent($topFolder, $searchPath)) {
                 break;
             }
             if (count($searchStack)) {
                 array_pop($searchStack);
             } else {
                 break;
             }
         }
     }
     return $templateNode;
 }
Ejemplo n.º 3
0
 public static function resolvePath($path, $checkParent = true, $checkCache = true)
 {
     // special case: request for root collection
     if (is_string($path) && (empty($path) || $path == '/')) {
         return new Emergence\DAV\RootCollection();
     }
     // parse path
     if (!is_array($path)) {
         $path = static::splitPath($path);
     }
     $collectionHandle = array_shift($path);
     // get root collection
     if (!$collectionHandle || !($collection = static::getRootCollection($collectionHandle))) {
         throw new Exception('Could not resolve root collection: ' . $collectionHandle);
     }
     // get node from collection
     $node = $collection->resolvePath($path);
     // try to get from parent
     if (!$node && $checkParent) {
         $node = Emergence::resolveFileFromParent($collectionHandle, $path);
     }
     if (!$node) {
         $node = null;
     }
     return $node;
 }
 public static function resolvePath($path, $checkParent = true)
 {
     if (is_string($path) && (empty($path) || $path == '/')) {
         return new SiteDavDirectory();
     } else {
         if (!is_array($path)) {
             $path = static::splitPath($path);
         }
         $collectionHandle = array_shift($path);
     }
     // get collection
     if (!$collectionHandle || !($collection = static::getRootCollection($collectionHandle))) {
         throw new Exception('Could not resolve root collection: ' . $collectionHandle);
     }
     // get file
     $node = $collection->resolvePath($path);
     // try to get from parent
     if (!$node && $checkParent) {
         $node = Emergence::resolveFileFromParent($collectionHandle, $path);
     }
     return $node;
 }
// TODO: something more elegant to prevent non-specified classes from being inherited?
Site::$autoPull = true;
$succeeded = array();
$failed = array();
foreach ($requestData['nodes'] as $updateData) {
    $Node = Site::resolvePath($updateData['path']);
    if ($Node->Collection->Site == 'Local') {
        $failed[] = array('path' => $updateData['path'], 'error' => 'CURRENT_IS_LOCAL', 'message' => 'Current node is local and blocks any remote updates');
        continue;
    }
    if ($Node->SHA1 != $updateData['localSHA1']) {
        $failed[] = array('path' => $updateData['path'], 'error' => 'LOCAL_SHA1_MISMATCH', 'message' => 'Current node\'s SHA1 hash does not match that which this update was requested for');
        continue;
    }
    if (empty($updateData['remoteSHA1'])) {
        $Node->delete();
    } else {
        $NewNode = Emergence::resolveFileFromParent($Node->Collection, $Node->Handle, true);
        if (!$NewNode) {
            $failed[] = array('path' => $updateData['path'], 'error' => 'DOWNLOAD_FAILED', 'message' => 'The remote file failed to download');
            continue;
        }
        if ($NewNode->SHA1 != $updateData['remoteSHA1']) {
            $NewNode->destroyRecord();
            $failed[] = array('path' => $updateData['path'], 'error' => 'REMOTE_SHA1_MISMATCH', 'message' => 'Downloaded node\'s SHA1 hash does not match that which this update was requested for');
            continue;
        }
    }
    $succeeded[] = $updateData['path'];
}
JSON::respond(array('succeeded' => $succeeded, 'failed' => $failed));