1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\ORM\Tests\DataObjectTest; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Dev\TestOnly; |
6
|
|
|
use SilverStripe\ORM\Connect\Query; |
7
|
|
|
use SilverStripe\ORM\DataObject; |
8
|
|
|
use SilverStripe\ORM\DB; |
9
|
|
|
use SilverStripe\ORM\HasManyList; |
10
|
|
|
use SilverStripe\ORM\Hierarchy\Hierarchy; |
11
|
|
|
use SilverStripe\ORM\ManyManyList; |
12
|
|
|
use SilverStripe\ORM\Queries\SQLUpdate; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The purpose of this test class is to test recursive writes and make sure we don't get stuck in an infinite loop. |
16
|
|
|
* @property int $WriteCount Number of times this object was written sine the last call of `resetCount` |
17
|
|
|
*/ |
18
|
|
|
class TreeNode extends DataObject implements TestOnly |
19
|
|
|
{ |
20
|
|
|
private static $table_name = 'DataObjectTest_TreeNode'; |
|
|
|
|
21
|
|
|
|
22
|
|
|
private static $db = [ |
|
|
|
|
23
|
|
|
'Title' => 'Varchar', |
24
|
|
|
'WriteCount' => 'Int' |
25
|
|
|
]; |
26
|
|
|
|
27
|
|
|
private static $has_one = [ |
|
|
|
|
28
|
|
|
'Parent' => self::class, |
29
|
|
|
'Cycle' => self::class, |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
private static $has_many = [ |
|
|
|
|
33
|
|
|
'Children' => self::class, |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
public function write($showDebug = false, $forceInsert = false, $forceWrite = false, $writeComponents = false) |
37
|
|
|
{ |
38
|
|
|
// Force the component to fetch its Parent and Cycle relation so we have components to recursively write |
39
|
|
|
$this->Parent; |
|
|
|
|
40
|
|
|
$this->Cycle; |
|
|
|
|
41
|
|
|
|
42
|
|
|
// Count a write attempts |
43
|
|
|
$this->WriteCount++; |
44
|
|
|
|
45
|
|
|
return parent::write($showDebug, $forceInsert, $forceWrite, $writeComponents); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Reset the WriteCount on all TreeNodes |
50
|
|
|
*/ |
51
|
|
|
public function resetCounts() |
52
|
|
|
{ |
53
|
|
|
$update = new SQLUpdate( |
54
|
|
|
sprintf('"%s"', self::baseTable()), |
|
|
|
|
55
|
|
|
['"WriteCount"' => 0] |
56
|
|
|
); |
57
|
|
|
$results = $update->execute(); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|