-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_bundle.php
executable file
·120 lines (100 loc) · 2.6 KB
/
_bundle.php
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
117
118
119
120
<?php
namespace Bundles\Taxonomy;
use Bundles\SQL\SQLBundle;
use Bundles\SQL\callException;
use Exception;
use e;
/**
* Taxonomy Bundle
* @author Kelly Becker
*/
class Bundle extends SQLBundle {
/**
* Extension for getTag to allow getting tags by name and category
* @author Kelly Becker
*/
public function __callExtend($func, $args) {
/**
* Create a variable to determine if were on stage one or two
* @author Kelly Becker
*/
static $run = 0;
/**
* If we are getting a tag, the argument passed is not numeric, and we havent been here before
* @author Kelly Becker
*/
if(($func == 'getTag' && !is_numeric($slug = $args[0])) && !is_array($slug) && $run < 1) {
/**
* If we dont detect a category then use "default"
* @author Kelly Becker
*/
if(strpos($slug, ':') === false) {
$category = 'default';
$name = $slug;
}
/**
* Since we have detected a category seperate it out
* @author Kelly Becker
*/
else list($category, $name) = explode(':', $slug, 2);
/**
* Run a query to find the requested tag
* @author Kelly Becker
*/
$result = e::$sql->query("SELECT * FROM `taxonomy.tag` WHERE `name` = '$name' AND `category` = '$category'")->row();
/**
* Since we got this far we dont want to go through this again if we fail
*/
$run++;
/**
* Get the model of the tag using the result of the query above
* @author Kelly Becker
*/
if($result) return $this->getTag($result);
/**
* If no tag was found create one and return it
* @author Kelly Becker
*/
else {
$tag = $this->newTag();
$tag->category = $category;
$tag->name = $name;
$tag->save();
$run = 0;
return $tag;
}
}
/**
* Since nothing was detected set run to zero so we can use the above script again
* @author Kelly Becker
*/
$run = 0;
/**
* Throw an exception telling the call method to run normally
* @author Kelly Becker
*/
throw new callException;
}
public function route() {
$tables = e::$sql->query("SHOW TABLES LIKE '\$tags%'")->all();
foreach($tables as &$table)
$table = array_shift($table);
foreach($tables as $table) {
$tags = e::$sql->query("SELECT * FROM `$table`")->all();
foreach($tags as $tag) {
if($tag['model'] !== 'taxonomy.tag')
continue;
$owner = $tag['owner'];
$id = $tag['model-id'];
$tag = $this->getTag($id);
e::$sql->update($table, array(
'string' => $tag->category.':'.$tag->name
), "WHERE `owner` = '$owner'");
$tag->__destruct();
unset($tag);
}
}
echo "Upgrade completed";
e\Complete();
}
}