-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathextension_generator_plugin.php
More file actions
122 lines (116 loc) · 4.87 KB
/
Copy pathextension_generator_plugin.php
File metadata and controls
122 lines (116 loc) · 4.87 KB
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
<?php
/**
* Extension Generator plugin handler
*
* @package blesta
* @subpackage plugins.extensiongenerator
* @copyright Copyright (c) 2020, Phillips Data, Inc.
* @license http://www.blesta.com/license/ The Blesta License Agreement
* @link http://www.blesta.com/ Blesta
*/
class ExtensionGeneratorPlugin extends Plugin
{
public function __construct()
{
// Load components required by this plugin
Loader::loadComponents($this, ['Input', 'Record']);
Language::loadLang('extension_generator_plugin', null, dirname(__FILE__) . DS . 'language' . DS);
$this->loadConfig(dirname(__FILE__) . DS . 'config.json');
}
/**
* Performs any necessary bootstraping actions
*
* @param int $plugin_id The ID of the plugin being installed
*/
public function install($plugin_id)
{
try {
// extension_generator_extensions
$this->Record->
setField('id', ['type' => 'int', 'size' => 10, 'unsigned' => true, 'auto_increment' => true])->
setField('company_id', ['type' => 'int', 'size' => 10, 'unsigned' => true])->
setField('name', ['type' => 'varchar', 'size' => 128])->
setField(
'type',
['type' => 'enum', 'size' => "'module','plugin','merchant','nonmerchant'", 'default' => 'module']
)->
setField('form_type', ['type' => 'enum', 'size' => "'basic','advanced'", 'default' => 'basic'])->
setField('code_examples', ['type' => 'tinyint', 'size' => 1, 'default' => 0])->
setField('data', ['type' => 'text', 'is_null' => true, 'default' => null])->
setField('date_updated', ['type' => 'datetime'])->
setKey(['id'], 'primary')->
setKey(['company_id'], 'index')->
create('extension_generator_extensions', true);
// Set the uploads directory
Loader::loadComponents($this, ['SettingsCollection', 'Upload']);
$temp = $this->SettingsCollection->fetchSetting(null, Configure::get('Blesta.company_id'), 'uploads_dir');
$upload_path = $temp['value'] . Configure::get('Blesta.company_id') . DS . 'extension_generator' . DS;
// Create the upload path if it doesn't already exist
$this->Upload->createUploadPath($upload_path, 0777);
} catch (Exception $e) {
// Error adding... no permission?
$this->Input->setErrors(['db' => ['create' => $e->getMessage()]]);
return;
}
}
/**
* Performs any necessary cleanup actions
*
* @param int $plugin_id The ID of the plugin being uninstalled
* @param bool $last_instance True if $plugin_id is the last instance across
* all companies for this plugin, false otherwise
*/
public function uninstall($plugin_id, $last_instance)
{
if ($last_instance) {
try {
$this->Record->drop('extension_generator_extensions');
} catch (Exception $e) {
// Error dropping... no permission?
$this->Input->setErrors(['db' => ['create' => $e->getMessage()]]);
return;
}
}
}
/**
* Performs migration of data from $current_version (the current installed version)
* to the given file set version
*
* @param string $current_version The current installed version of this plugin
* @param int $plugin_id The ID of the plugin being upgraded
*/
public function upgrade($current_version, $plugin_id)
{
// Upgrade if possible
if (version_compare($this->getVersion(), $current_version, '>')) {
// Handle the upgrade, set errors using $this->Input->setErrors() if any errors encountered
if (version_compare($current_version, '1.1.0', '<')) {
$this->Record->query(
"ALTER TABLE `extension_generator_extensions` CHANGE `type` `type`
ENUM('module', 'plugin', 'merchant', 'nonmerchant') NOT NULL DEFAULT 'module'"
);
}
}
}
/**
* Returns all actions to be configured for this widget (invoked after install()
* or upgrade(), overwrites all existing actions)
*
* @return array A numerically indexed array containing:
* - action The action to register for
* - uri The URI to be invoked for the given action
* - name The name to represent the action
* - options An array of options (optional)
*/
public function getActions()
{
return [
[
'action' => 'nav_secondary_staff',
'uri' => 'plugin/extension_generator/admin_main/',
'name' => 'ExtensionGeneratorPlugin.nav_secondary_staff.admin_main',
'options' => ['parent' => 'tools/']
]
];
}
}