1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* phpBB Directory extension for the phpBB Forum Software package. |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2014 ErnadoO <http://www.phpbb-services.com> |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ernadoo\phpbbdirectory\migrations\v20x; |
12
|
|
|
|
13
|
|
|
class add_cat_route_field extends \phpbb\db\migration\migration |
14
|
|
|
{ |
15
|
|
|
static public function depends_on() |
16
|
|
|
{ |
17
|
|
|
return array( |
18
|
|
|
'\ernadoo\phpbbdirectory\migrations\v10x\v1_0_0', |
19
|
|
|
); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @inheritDoc |
24
|
|
|
*/ |
25
|
|
|
public function update_schema() |
26
|
|
|
{ |
27
|
|
|
return array( |
28
|
|
|
'add_columns' => array( |
29
|
|
|
$this->table_prefix . 'directory_cats' => array( |
30
|
|
|
'cat_route' => array('VCHAR', '', 'after' => 'cat_name'), |
31
|
|
|
) |
32
|
|
|
), |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @inheritDoc |
38
|
|
|
*/ |
39
|
|
|
public function update_data() |
40
|
|
|
{ |
41
|
|
|
return array( |
42
|
|
|
array('custom', array(array($this, 'rewrite_cat_name'))), |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @inheritDoc |
48
|
|
|
*/ |
49
|
|
|
public function revert_schema() |
50
|
|
|
{ |
51
|
|
|
return array( |
52
|
|
|
'drop_columns' => array( |
53
|
|
|
$this->table_prefix . 'directory_cats' => array( |
54
|
|
|
'cat_route', |
55
|
|
|
), |
56
|
|
|
), |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function rewrite_cat_name() |
61
|
|
|
{ |
62
|
|
|
$slug = new \E1379\SpeakingUrl\SpeakingUrl(); |
63
|
|
|
|
64
|
|
|
$sql = 'SELECT cat_id, cat_name FROM ' . $this->table_prefix . 'directory_cats'; |
65
|
|
|
$result = $this->db->sql_query($sql); |
66
|
|
|
|
67
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
68
|
|
|
{ |
69
|
|
|
$sql = 'UPDATE ' . $this->table_prefix . 'directory_cats' . ' |
70
|
|
|
SET cat_route = "' . (string) $slug->getSlug($row['cat_name'], array('lang' => $this->config['default_lang'], 'symbols' => true)). '" |
71
|
|
|
WHERE cat_id = ' . (int) $row['cat_id']; |
72
|
|
|
$this->db->sql_query($sql); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|