Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Change how recycle bin is filter, not on input but on output, otherwi…
Browse files Browse the repository at this point in the history
…se restoration is not correctly detected

We could use this index to compute quotas in various configurations
  • Loading branch information
cdujeu committed Jul 30, 2014
1 parent 8053aa6 commit d73217f
Showing 1 changed file with 43 additions and 8 deletions.
51 changes: 43 additions & 8 deletions core/src/plugins/meta.syncable/class.ChangesTracker.php
Expand Up @@ -53,6 +53,8 @@ public function switchActions($actionName, $httpVars, $fileVars)
dibi::connect($this->sqlDriver);
$filter = null;
$currentRepo = $this->accessDriver->repository;
$recycle = $currentRepo->getOption("RECYCLE_BIN");
$recycle = (!empty($recycle)?$recycle:false);

HTMLWriter::charsetHeader('application/json', 'UTF-8');
if(isSet($httpVars["filter"])){
Expand Down Expand Up @@ -90,6 +92,7 @@ public function switchActions($actionName, $httpVars, $fileVars)
$row->node[$att] = $row->$att;
unset($row->$att);
}
if(!empty($recycle)) $this->cancelRecycleNodes($row, $recycle);
if(!isSet($httpVars["flatten"]) || $httpVars["flatten"] == "false"){

if(!$this->filterRow($row, $filter)){
Expand Down Expand Up @@ -126,13 +129,21 @@ public function switchActions($actionName, $httpVars, $fileVars)
$lastSeq = $row->seq;
flush();
}
if (isSet($previousRow) && ($previousRow->source != $previousRow->target || $previousRow->type == "content") && !$this->filterRow($previousRow, $filter)) {
if($valuesSent) echo $separator;
echo json_encode($previousRow);
$valuesSent = true;
}
//CODES HERE HAVE BEEN MOVE OUT OF THE LOOP
}

/**********RETURN TO SENDER************/
// is 'not NULL' included in isSet()?
if ($previousRow && isSet($previousRow) && ($previousRow->source != $previousRow->target || $previousRow->type == "content") && !$this->filterRow($previousRow, $filter)) {
if($valuesSent) echo $separator;
echo json_encode($previousRow);
if ($previousRow->seq > $lastSeq){
$lastSeq = $previousRow->seq;
}
$valuesSent = true;
}
/*************************************/

if (isSet($lastSeq)) {
if($stream){
echo("\nLAST_SEQ:".$lastSeq);
Expand All @@ -151,6 +162,18 @@ public function switchActions($actionName, $httpVars, $fileVars)

}

protected function cancelRecycleNodes(&$row, $recycle){
if($row->type != 'path') return;
if(strpos($row->source, '/'.$recycle) === 0){
$row->source = 'NULL';
$row->type = 'create';
}else if(strpos($row->target, '/'.$recycle) === 0){
$row->target = 'NULL';
$row->type = 'delete';
$row->node = array();
}
}

protected function filterRow(&$previousRow, $filter = null){
if($filter == null) return false;
$srcInFilter = strpos($previousRow->source, $filter) === 0;
Expand Down Expand Up @@ -196,6 +219,16 @@ protected function computeIdentifier($repository)
return implode("-", $parts);
}

/**
* @param Repository $repository
* @return float
*/
public function getRepositorySpaceUsage($repository){
$id = $this->computeIdentifier($repository);
$res = dibi::query("SELECT SUM([bytesize]) FROM [ajxp_index] WHERE [repository_identifier] = %s", $id);
return floatval($res->fetchSingle());
}

/**
* @param AJXP_Node $oldNode
* @param AJXP_Node $newNode
Expand Down Expand Up @@ -269,9 +302,11 @@ public function updateNodesIndex($oldNode = null, $newNode = null, $copy = false
* @return bool
*/
protected function excludeNode($node){
$repo = $node->getRepository();
$recycle = $repo->getOption("RECYCLE_BIN");
if(!empty($recycle) && strpos($node->getPath(), "/".trim($recycle, "/")) === 0) return true;
// DO NOT EXCLUDE RECYCLE INDEXATION, OTHERWISE RESTORED DATA IS NOT DETECTED!
//$repo = $node->getRepository();
//$recycle = $repo->getOption("RECYCLE_BIN");
//if(!empty($recycle) && strpos($node->getPath(), "/".trim($recycle, "/")) === 0) return true;

// Other exclusions conditions here?
return false;
}
Expand Down

0 comments on commit d73217f

Please sign in to comment.