This repository has been archived by the owner on Jul 6, 2021. It is now read-only.
/
upd.simple_cloner.php
executable file
·207 lines (180 loc) · 4.66 KB
/
upd.simple_cloner.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once PATH_THIRD . 'simple_cloner/config.php';
/**
* Simple Cloner Update class
*
* @package simple_cloner
* @author Stuart Thornton <sthornton@knightknox.com>
* @link http://www.github.com/ThorntonStuart
* @copyright Copyright (c) 2016, Stuart Thornton
*/
class Simple_cloner_upd {
var $version = SIMPLE_CLONER_VER;
var $class_name = SIMPLE_CLONER_NAME_FORMATTED;
public function __construct()
{
}
/**
* Install the module
*
* @return bool
*/
public function install() {
// Insert data to modules table.
$data = array(
'module_name' => 'Simple_cloner',
'module_version' => $this->version,
'has_cp_backend' => 'y',
'has_publish_fields' => 'y'
);
ee()->db->insert('modules', $data);
// Load settings library and DBForge class.
ee()->load->library('simple_cloner_settings');
ee()->load->dbforge();
// Create Simple Cloner Content table and insert table fields.
$simple_cloner_content_fields = array(
'simple_cloner_content_id' => array(
'type' => 'int',
'constraint' => '10',
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'site_id' => array(
'type' => 'int',
'constraint' => '10',
'null' => FALSE
),
'entry_id' => array(
'type' => 'int',
'constraint' => '10',
'null' => FALSE
),
'cloned_entry_status' => array(
'type' => 'varchar',
'constraint' => '1024'
),
'title_suffix' => array(
'type' => 'varchar',
'constraint' => '1024'
),
'url_title_suffix' => array(
'type' => 'varchar',
'constraint' => '1024'
),
'update_entry_time' => array(
'type' => 'varchar',
'constraint' => '1024'
),
'clone_entry' => array(
'type' => 'varchar',
'constraint' => '1024',
'null' => FALSE
)
);
ee()->dbforge->add_field($simple_cloner_content_fields);
ee()->dbforge->add_key('simple_cloner_content_id', TRUE);
ee()->dbforge->create_table('simple_cloner_content');
// Execute hook insertion to set up extension in database.
$this->_insert_hook();
// Add Simple Cloner tab to publish form.
ee()->load->library('layout');
ee()->layout->add_layout_tabs($this->tabs(), 'simple_cloner');
return TRUE;
}
/**
* Update the module
*
* @return bool
*/
public function update($current = '') {
ee()->load->dbforge();
if($current == $this->version) {
return FALSE;
}
if(version_compare($current, '2.0.0', '<')) {
$simple_cloner_content_2_0_0 = array(
'cloned_entry_status' => array(
'type' => 'varchar',
'constraint' => '1024'
)
);
ee()->dbforge->add_column('simple_cloner_content', $simple_cloner_content_2_0_0);
}
return TRUE;
}
/**
* Uninstall the module
*
* @return bool
*/
public function uninstall() {
// Load DBForge class.
ee()->load->dbforge();
// Find module in table and remove row.
ee()->db->where('module_name', $this->class_name);
ee()->db->delete('modules');
// Find extension in table and remove row.
ee()->db->where('class', $this->class_name.'_ext');
ee()->db->delete('extensions');
// Drop Simple Cloner Content table.
ee()->dbforge->drop_table('simple_cloner_content');
// Remove Simple Cloner tab from publish layout.
ee()->load->library('layout');
ee()->layout->delete_layout_tabs($this->tabs(), 'simple_cloner');
return TRUE;
}
public function tabs()
{
$tabs['simple_cloner'] = array(
'cloned_entry_status' => array(
'visible' => 'true',
'collapse' => 'false',
'htmlbuttons' => 'true',
'width' => '100%'
),
'title_suffix' => array(
'visible' => 'true',
'collapse' => 'false',
'htmlbuttons' => 'true',
'width' => '100%'
),
'url_title_suffix' => array(
'visible' => 'true',
'collapse' => 'false',
'htmlbuttons' => 'true',
'width' => '100%'
),
'update_entry_time' => array(
'visible' => 'true',
'collapse' => 'false',
'htmlbuttons' => 'true',
'width' => '100%'
),
'clone_entry' => array(
'visible' => 'true',
'collapse' => 'false',
'htmlbuttons' => 'true',
'width' => '100%'
)
);
return $tabs;
}
/**
* Install the extension
*
*/
private function _insert_hook()
{
// Define extension columns and insert to exp_extensions table.
$data = array(
'class' => $this->class_name.'_ext',
'method' => 'simple_cloner_content_save',
'hook' => 'after_channel_entry_save',
'settings' => serialize(ee()->simple_cloner_settings->get()),
'priority' => 10,
'version' => $this->version,
'enabled' => 'y'
);
ee()->db->insert('extensions', $data);
}
}