blob: b1df3c7e450aff04e4b26a10245ada12c4aa4048 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
<?php
/**
*
* @package Nested Set
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
class phpbb_nestedset_forum extends phpbb_nestedset_base
{
/** @var phpbb_db_driver */
protected $db;
/** @var phpbb_lock_db */
protected $lock;
/** @var String */
protected $table_name;
/** @var String */
protected $item_class = 'phpbb_nestedset_item_forum';
/**
* Column names in the table
* @var String
*/
protected $columns_item_id = 'forum_id';
protected $columns_item_parents = 'forum_parents';
/**
* Additional SQL restrictions
* Allows to have multiple nestedsets in one table
* Columns must be prefixed with %1$s
* @var String
*/
protected $sql_where = '';
/**
* List of item properties to be cached in $item_parents
* @var array
*/
protected $item_basic_data = array('forum_id', 'forum_name', 'forum_type');
/**
* Construct
*
* @param phpbb_db_driver $db Database connection
* @param phpbb_lock_db $lock Lock class used to lock the table when moving forums around
* @param string $table_name Table name
*/
public function __construct(phpbb_db_driver $db, phpbb_lock_db $lock, $table_name)
{
$this->db = $db;
$this->lock = $lock;
$this->table_name = $table_name;
}
/**
* @inheritdoc
*/
public function move_children(phpbb_nestedset_item_interface $current_parent, phpbb_nestedset_item_interface $new_parent)
{
while (!$this->lock->acquire())
{
// Retry after 0.2 seconds
usleep(200 * 1000);
}
try
{
$return = parent::move_children($current_parent, $new_parent);
}
catch (phpbb_nestedset_exception $e)
{
$this->lock->release();
throw new phpbb_nestedset_exception('FORUM_NESTEDSET_' . $e->getMessage());
}
$this->lock->release();
return $return;
}
/**
* @inheritdoc
*/
public function set_parent(phpbb_nestedset_item_interface $item, phpbb_nestedset_item_interface $new_parent)
{
while (!$this->lock->acquire())
{
// Retry after 0.2 seconds
usleep(200 * 1000);
}
try
{
$return = parent::set_parent($item, $new_parent);
}
catch (phpbb_nestedset_exception $e)
{
$this->lock->release();
throw new phpbb_nestedset_exception('FORUM_NESTEDSET_' . $e->getMessage());
}
$this->lock->release();
return $return;
}
}
|