Implement the Plugin sql updates

I checked the JCB codes and tried to implement the plugin sql updates section that did not work according to the JCB structure
This commit is contained in:
saman222 2021-12-26 14:13:18 +03:30
parent 9373b29bff
commit c37dfc0b21
6 changed files with 152 additions and 11 deletions

View File

@ -221,6 +221,13 @@
}
},
"dynamic": {
"plugin": {
"1.0.0.sql": {
"path": "P|uG!n/sql/mysql/updates",
"rename": "1.0.0",
"type": "sql_update"
}
},
"admin": {
"whmcs.php": {
"path": "c0mp0n3nt/admin",

View File

@ -580,7 +580,7 @@ class Compiler extends Infusion
{
$this->setFileContent(
$plugin_file['name'], $plugin_file['path'],
$bom, $plugin->key
$bom, ['plugin_key' => $plugin->key, 'view' => $plugin_file['view']]
);
}
}
@ -633,6 +633,12 @@ class Compiler extends Infusion
*/
protected function setFileContent(&$name, &$path, &$bom, $view = null)
{
$main_view= null;
if (is_array($view))
{
$main_view= $view['view'];
$view= $view['plugin_key'];
}
// Trigger Event: jcb_ce_onBeforeSetFileContent
$this->triggerEvent(
'jcb_ce_onBeforeSetFileContent',
@ -667,9 +673,20 @@ class Compiler extends Infusion
// set the dynamic answer
if ($view)
{
$answer = $this->setPlaceholders(
$answer, $this->fileContentDynamic[$view], 3
);
if ($main_view)
{
$answer = $this->setPlaceholders(
$answer, $this->fileContentDynamic[$view][$main_view], 3
);
}
else
{
$answer = $this->setPlaceholders(
$answer, $this->fileContentDynamic[$view], 3
);
}
}
// check if this file needs extra care :)
if (isset($this->updateFileContent[$path]))

View File

@ -10639,6 +10639,15 @@ class Get
$plugin->{$server . '_protocol'} = 0;
}
}
$plugin->version_update = (isset($plugin->version_update)
&& ComponentbuilderHelper::checkJson($plugin->version_update))
? json_decode($plugin->version_update, true) : null;
if (ComponentbuilderHelper::checkArray($plugin->version_update))
{
$plugin->version_update = array_values(
$plugin->version_update
);
}
// set the update server stuff (TODO)
// update_server_xml_path
// update_server_xml_file_name

View File

@ -1396,7 +1396,8 @@ class Structure extends Get
}
}
// set SQL stuff if needed
if ($plugin->add_sql || $plugin->add_sql_uninstall)
if ($plugin->add_sql || $plugin->add_sql_uninstall || $plugin->version_update)
{
// create SQL folder
$this->createFolder($plugin->folder_path . '/sql');
@ -2716,7 +2717,7 @@ class Structure extends Get
*
*/
public function buildDynamique($target, $type, $fileName = false,
$config = false
$config = false, $plugin= null
)
{
// did we build the files (any number)
@ -2755,6 +2756,13 @@ class Structure extends Get
'c0mp0n3nt/', $this->componentPath . '/', $path
);
}
elseif (strpos($path, 'P|uG!n') !== false)
{
$zipPath = str_replace('P|uG!n/', '', $path);
$path = str_replace(
'P|uG!n/', $plugin->folder_path . '/', $path
);
}
else
{
$this->app->enqueueMessage(
@ -2770,7 +2778,10 @@ class Structure extends Get
if (!Folder::exists($path))
{
Folder::create($path);
$this->indexHTML($zipPath);
if (!empty($plugin))
$this->indexHTML($zipPath,'plugin', $plugin);
else
$this->indexHTML($zipPath);
// count the folder created
$this->folderCount++;
}
@ -2817,8 +2828,14 @@ class Structure extends Get
{
$newFIle['config'] = $config;
}
// store the new files
$this->newFiles['dynamic'][$name][] = $newFIle;
// store the new files
if (!empty($plugin))
$this->newFiles[$plugin->key][$name] = $newFIle;
else
$this->newFiles['dynamic'][$name][] = $newFIle;
// we have build atleast one
$build_status = true;
}
@ -3148,12 +3165,16 @@ class Structure extends Get
* @return void
*
*/
private function indexHTML($path, $root = 'component')
private function indexHTML($path, $root = 'component', $plugin= null)
{
if ('component' === $root)
{
$root = $this->componentPath . '/';
}
if ('plugin' === $root)
{
$root = $plugin->folder_path . '/';
}
// use path if exist
if (strlen($path) > 0)
{

View File

@ -1095,6 +1095,43 @@ class Interpretation extends Fields
return '';
}
/**
* set plugin Version Controller
*/
public function setPluginVersionController(&$plugin)
{
if (ComponentbuilderHelper::checkArray(
$plugin->version_update
))
{
$updateXML = array();
// add the dynamic sql switch
$addDynamicSQL = true;
$addActive = true;
if (ComponentbuilderHelper::checkArray(
$plugin->version_update
))
{
foreach (
$plugin->version_update as $nr => &$update
)
{
$this->setPluginUpdateXMLSQL($update, $updateXML, $addDynamicSQL, $plugin);
if ($update['version']
== $plugin->plugin_version)
{
$addActive = false;
}
}
}
}
}
/**
* set Version Controller
*/
@ -1307,6 +1344,40 @@ class Interpretation extends Fields
$this->setUpdateXMLSQL($update_, $updateXML, $addDynamicSQL);
}
/**
* set plugin Update XML SQL
*
* @param array $update
* @param array $updateXML
* @param boolean $addDynamicSQL
*/
public function setPluginUpdateXMLSQL(&$update, &$updateXML, &$addDynamicSQL, $plugin)
{
// ensure version naming is correct
$update['version'] = preg_replace('/[^0-9.]+/', '', $update['version']);
// setup SQL
if (ComponentbuilderHelper::checkString($update['mysql']))
{
$update['mysql'] = $this->setPlaceholders(
$update['mysql'], $this->placeholders
);
}
// setup import files
if ($update['version'] != $plugin->plugin_version)
{
$name = ComponentbuilderHelper::safeString($update['version']);
$target = array('plugin' => $name);
$this->buildDynamique($target, 'sql_update', $update['version'], false, $plugin);
$this->fileContentDynamic[$plugin->key][$name . '_'
. $update['version']][$this->hhh . 'UPDATE_VERSION_MYSQL'
. $this->hhh]
= $update['mysql'];
}
}
/**
* set Update XML SQL
*
@ -28790,6 +28861,19 @@ function vdm_dkim() {
$xml .= PHP_EOL . $this->_t(2) . '</sql>';
$xml .= PHP_EOL . $this->_t(1) . '</uninstall>';
}
// should the sql update be added
if ($plugin->version_update)
{
$xml .= PHP_EOL . PHP_EOL . $this->_t(1) . '<!--' . $this->setLine(
__LINE__
) . ' Runs on update; New in Joomla 1.5 -->';
$xml .= PHP_EOL . $this->_t(1) . '<update>';
$xml .= PHP_EOL . $this->_t(2) . '<schemas>';
$xml .= PHP_EOL . $this->_t(3)
. '<schemapath type="mysql">sql/mysql/updates/</schemapath>';
$xml .= PHP_EOL . $this->_t(2) . '</schemas>';
$xml .= PHP_EOL . $this->_t(1) . '</update>';
}
// should the language xml be added
if (ComponentbuilderHelper::checkArray($addLang))
{
@ -28840,7 +28924,7 @@ function vdm_dkim() {
$xml .= PHP_EOL . $this->_t(2) . '<folder>language</folder>';
}
// add sql folder
if ($plugin->add_sql || $plugin->add_sql_uninstall)
if ($plugin->add_sql || $plugin->add_sql_uninstall || $plugin->version_update)
{
$xml .= PHP_EOL . $this->_t(2) . '<folder>sql</folder>';
}

View File

@ -2454,6 +2454,9 @@ class Infusion extends Interpretation
. 'INSTALLCLASS' . $this->hhh]
= $this->getExtensionInstallClass($plugin);
}
$this->setPluginVersionController($plugin);
// FIELDSET
if (isset($plugin->form_files)
&& ComponentbuilderHelper::checkArray(