Skip to content

Commit 8ae6489

Browse files
committed
Support order of tree operations
1 parent d3c7808 commit 8ae6489

File tree

6 files changed

+279
-62
lines changed

6 files changed

+279
-62
lines changed

lib/Doctrine/ODM/PHPCR/DocumentManager.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,9 @@ public function findMany($className, array $ids)
389389
}
390390

391391
$nodes = $this->session->getNodes($ids);
392-
$hints = array('fallback' => true);
392+
$hints = array(
393+
'fallback' => true,
394+
);
393395
$documents = $this->unitOfWork->getOrCreateDocuments($className, $nodes, $hints);
394396

395397
return new ArrayCollection($documents);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Doctrine\ODM\PHPCR\Queue;
4+
5+
class TreeOperation
6+
{
7+
const OP_MOVE = 'move';
8+
const OP_REMOVE = 'remove';
9+
const OP_INSERT = 'insert';
10+
11+
private $oid;
12+
private $type;
13+
private $args;
14+
private $valid = true;
15+
16+
public function __construct($type, $oid, $args)
17+
{
18+
$this->oid = $oid;
19+
$this->type = $type;
20+
$this->args = $args;
21+
}
22+
23+
public function getOid()
24+
{
25+
return $this->oid;
26+
}
27+
28+
public function getType()
29+
{
30+
return $this->type;
31+
}
32+
33+
public function getArgs()
34+
{
35+
return $this->args;
36+
}
37+
38+
public function invalidate()
39+
{
40+
$this->valid = false;
41+
}
42+
43+
public function isValid()
44+
{
45+
return $this->valid;
46+
}
47+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Doctrine\ODM\PHPCR\Queue;
4+
5+
class TreeOperationBatch
6+
{
7+
private $type;
8+
private $schedule = array();
9+
10+
public function __construct($type)
11+
{
12+
$this->type = $type;
13+
}
14+
15+
public function getSchedule()
16+
{
17+
return $this->schedule;
18+
}
19+
20+
public function schedule($oid, $args)
21+
{
22+
$this->schedule[$oid] = $args;
23+
}
24+
25+
public function getType()
26+
{
27+
return $this->type;
28+
}
29+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
3+
namespace Doctrine\ODM\PHPCR\Queue;
4+
5+
use Doctrine\ODM\PHPCR\Queue\TreeOperation;
6+
use Doctrine\ODM\PHPCR\Queue\TreeOperationBatch;
7+
8+
class TreeOperationQueue
9+
{
10+
private $queue = array();
11+
12+
public function push(TreeOperation $operation)
13+
{
14+
$this->queue[] = $operation;
15+
}
16+
17+
/**
18+
* Partition into contiguous sets of operations
19+
*/
20+
public function getBatches()
21+
{
22+
$type = null;
23+
$batches = array();
24+
25+
foreach ($this->queue as $operation) {
26+
if (false === $operation->isValid()) {
27+
continue;
28+
}
29+
30+
if ($operation->getType() !== $type) {
31+
$batch = new TreeOperationBatch($operation->getType());
32+
$type = $operation->getType();
33+
$batches[] = $batch;
34+
}
35+
36+
$batch->schedule(
37+
$operation->getOid(),
38+
$operation->getArgs()
39+
);
40+
}
41+
42+
return $batches;
43+
}
44+
45+
public function clear()
46+
{
47+
$this->queue = array();
48+
}
49+
50+
public function getSchedule($type)
51+
{
52+
$schedule = array();
53+
54+
foreach ($this->queue as $operation) {
55+
if (false === $operation->isValid()) {
56+
continue;
57+
}
58+
59+
$schedule[$operation->getOid()] = $operation->getArgs();
60+
}
61+
62+
return $schedule;
63+
}
64+
65+
public function isQueued($type, $oid)
66+
{
67+
foreach ($this->queue as $operation) {
68+
if (false === $operation->isValid()) {
69+
continue;
70+
}
71+
72+
if ($operation->getType() !== $type) {
73+
continue;
74+
}
75+
76+
if ($oid == $operation->getOid()) {
77+
return true;
78+
}
79+
}
80+
81+
return false;
82+
}
83+
84+
public function unqueue($type, $oid)
85+
{
86+
foreach ($this->queue as $operation) {
87+
if ($operation->getType() !== $type) {
88+
continue;
89+
}
90+
91+
if ($operation->getOid() !== $oid) {
92+
continue;
93+
}
94+
95+
$operation->invalidate();
96+
}
97+
}
98+
99+
public function unregister($oid)
100+
{
101+
foreach ($this->queue as $operation) {
102+
if ($operation->getOid() == $oid) {
103+
$operation->invalidate();
104+
}
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)