Example #1
0
function buildDirModel($dir, $model, $rootname)
{
    ##Remove from $dir to output the part until s3db root;
    $dirFiles = scandir($dir);
    foreach ($dirFiles as $ind) {
        if (is_file($dir . '/' . $ind) && !ereg('^(s3id|config.inc.php|treeitem.*.js)', $ind)) {
            $fstat = lstat($dir . '/' . $ind);
            $lastModified = date('Y-m-d H:i:s', $fstat['mtime']);
            $path = str_replace($rootname, '', $dir);
            $path = $path == '' ? $ind : substr($path, 1, strlen($path)) . '/' . $ind;
            $subjResources = new Resource('http://www.s3db.org/central/s3dbfiles.php?file=' . $path);
            $statement = new Statement($subjResources, new Resource('http://purl.org/dc/elements/1.1/date'), new Literal($lastModified));
            $path = new Statement($subjResources, new Resource('http://s3db.org/scripts'), new Literal($path));
            $model->add($statement);
            $model->add($path);
        } elseif (is_dir($dir . '/' . $ind) && !ereg('^(.|..|extras)$', $ind)) {
            $newDir = $dir . '/' . $ind;
            $submodel = ModelFactory::getDefaultModel();
            $submodel = buildDirModel($newDir, $submodel, $rootname);
            $model->addModel($submodel);
        }
    }
    return $model;
}
Example #2
0
function buildDirModel($dir, $model, $rootname, $user_id, $db)
{
    ##Remove from $dir to output the part until s3db root;
    $dirFiles = scandir($dir);
    #echo '<pre>';print_r($dirFiles);exit;
    #foreach ($dirFiles as $ind)
    for ($i = 0; $i < count($dirFiles); $i++) {
        $ind = $dirFiles[$i];
        if (is_file($dir . '/' . $ind) && !ereg('^(s3id|config.inc.php|treeitem.*.js|.*.tmp|.*[0-9]{8}$)', $ind)) {
            $fstat = lstat($dir . '/' . $ind);
            $lastModified = date('Y-m-d H:i:s', $fstat['mtime']);
            $path = str_replace($rootname, '', $dir);
            $path = $path == '' ? $ind : substr($path, 1, strlen($path)) . '/' . $ind;
            $path = addslashes($path);
            ###
            #Is there an item with this path value on path rule?
            #$item_id = findFileItemId($path,$user_id,$db);
            ###
            #Find the statement_id of this file on the local s3db
            $allFileIds = @file_get_contents('fileIds.tmp');
            $allFileIds = @unserialize($allFileIds);
            $file_id = @array_search($path, $allFileIds);
            if ($file_id == '') {
                echo "Finding ID of file " . $path . chr(10);
                $sql = "select statement_id from s3db_statement where rule_id = '" . $GLOBALS['update_project']['file']['rule_id'] . "' and file_name = '" . $path . "' order by created_on desc limit 1";
                $db->query($sql, __LINE__, __FILE__);
                if ($db->next_record()) {
                    $file_id = $db->f('statement_id');
                    $allFileIds[$file_id] = $path;
                }
            }
            if ($file_id == '') {
                $updated = fileUpdate($path, $user_id, $db);
                $file_id = $updated;
            }
            if ($file_id != '') {
                file_put_contents('fileIds.tmp', serialize($allFileIds));
                echo "writting item " . $path . " " . $file_id . chr(10);
                $subjResources = new Resource($GLOBALS['s3db_info']['deployment']['URI'] . 's3dbfiles.php?file_id=' . $file_id);
                $statement = new Statement($subjResources, new Resource('http://purl.org/dc/elements/1.1/date'), new Literal($lastModified));
                $path = new Statement($subjResources, new Resource('http://s3db.org/scripts'), new Literal($path));
                $model->add($statement);
                $model->add($path);
            } else {
                @file_put_contents('update_error_log.txt', "Could not find a file_id for " . $path . chr(10));
            }
        } elseif (is_dir($dir . '/' . $ind) && !ereg('^(.|..|extras)$', $ind)) {
            $newDir = $dir . '/' . $ind;
            $submodel = ModelFactory::getDefaultModel();
            $submodel = buildDirModel($newDir, $submodel, $rootname, $user_id, $db);
            $model->addModel($submodel);
        }
    }
    return $model;
}