From c37dfc0b21abe194a30e626fc79dc059fe2d5c54 Mon Sep 17 00:00:00 2001 From: saman222 Date: Sun, 26 Dec 2021 14:13:18 +0330 Subject: [PATCH 1/2] 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 --- admin/compiler/joomla_3/settings.json | 7 ++ admin/helpers/compiler.php | 25 +++++- admin/helpers/compiler/a_Get.php | 9 +++ admin/helpers/compiler/b_Structure.php | 33 ++++++-- admin/helpers/compiler/e_Interpretation.php | 86 ++++++++++++++++++++- admin/helpers/compiler/f_Infusion.php | 3 + 6 files changed, 152 insertions(+), 11 deletions(-) diff --git a/admin/compiler/joomla_3/settings.json b/admin/compiler/joomla_3/settings.json index edfe475a9..3e5bfec73 100644 --- a/admin/compiler/joomla_3/settings.json +++ b/admin/compiler/joomla_3/settings.json @@ -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", diff --git a/admin/helpers/compiler.php b/admin/helpers/compiler.php index 06c4e9d02..32759a37a 100644 --- a/admin/helpers/compiler.php +++ b/admin/helpers/compiler.php @@ -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])) diff --git a/admin/helpers/compiler/a_Get.php b/admin/helpers/compiler/a_Get.php index 6fe093539..758b9cc78 100644 --- a/admin/helpers/compiler/a_Get.php +++ b/admin/helpers/compiler/a_Get.php @@ -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 diff --git a/admin/helpers/compiler/b_Structure.php b/admin/helpers/compiler/b_Structure.php index 79532517f..17fee9ad4 100644 --- a/admin/helpers/compiler/b_Structure.php +++ b/admin/helpers/compiler/b_Structure.php @@ -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) { diff --git a/admin/helpers/compiler/e_Interpretation.php b/admin/helpers/compiler/e_Interpretation.php index 2c20bd99c..0e2632cdb 100644 --- a/admin/helpers/compiler/e_Interpretation.php +++ b/admin/helpers/compiler/e_Interpretation.php @@ -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) . ''; $xml .= PHP_EOL . $this->_t(1) . ''; } + // should the sql update be added + if ($plugin->version_update) + { + $xml .= PHP_EOL . PHP_EOL . $this->_t(1) . ''; + $xml .= PHP_EOL . $this->_t(1) . ''; + $xml .= PHP_EOL . $this->_t(2) . ''; + $xml .= PHP_EOL . $this->_t(3) + . 'sql/mysql/updates/'; + $xml .= PHP_EOL . $this->_t(2) . ''; + $xml .= PHP_EOL . $this->_t(1) . ''; + } // should the language xml be added if (ComponentbuilderHelper::checkArray($addLang)) { @@ -28840,7 +28924,7 @@ function vdm_dkim() { $xml .= PHP_EOL . $this->_t(2) . 'language'; } // 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) . 'sql'; } diff --git a/admin/helpers/compiler/f_Infusion.php b/admin/helpers/compiler/f_Infusion.php index 4cd4ccc89..cc9584d0b 100644 --- a/admin/helpers/compiler/f_Infusion.php +++ b/admin/helpers/compiler/f_Infusion.php @@ -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( -- 2.40.1 From d57f35fc006ce1dc189bf5af30358e6cf2e8891c Mon Sep 17 00:00:00 2001 From: saman222 Date: Wed, 23 Feb 2022 13:31:56 +0330 Subject: [PATCH 2/2] correct the name of the editors-xtd group plugins class editors-xtd group plugins class name must have a (plgButton) structure, but JCB creates the names of these classes with (plg) structure, which makes this type of plugins not work --- admin/helpers/compiler/a_Get.php | 4 +--- admin/helpers/componentbuilder.php | 18 ++++++++++++++++-- site/helpers/componentbuilder.php | 17 ++++++++++++++++- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/admin/helpers/compiler/a_Get.php b/admin/helpers/compiler/a_Get.php index b4a0377f1..5e9a411b9 100644 --- a/admin/helpers/compiler/a_Get.php +++ b/admin/helpers/compiler/a_Get.php @@ -10149,9 +10149,7 @@ class Get // set lang prefix $plugin->lang_prefix = $this->langPrefix; // set plugin class name - $plugin->class_name = 'Plg' . ucfirst($plugin->group) . ucfirst( - $plugin->code_name - ); + $plugin->class_name = ComponentbuilderHelper::createPluginClassName($plugin->group, $plugin->code_name); // set plugin install class name $plugin->installer_class_name = 'plg' . ucfirst($plugin->group) . ucfirst($plugin->code_name) . 'InstallerScript'; diff --git a/admin/helpers/componentbuilder.php b/admin/helpers/componentbuilder.php index 99c85408c..49fa4b2b0 100644 --- a/admin/helpers/componentbuilder.php +++ b/admin/helpers/componentbuilder.php @@ -6587,8 +6587,22 @@ abstract class ComponentbuilderHelper return array_values($fieldIds); } return false; - } - + } + + /** + * create plugin class name + */ + public static function createPluginClassName($group, $code_name) + { + // editors-xtd group plugins must have a class with plgButton structure + if ($group == 'editors-xtd') + $group= 'Button'; + + return 'Plg' . ucfirst($group) . ucfirst( + $code_name + ); + } + /** * get a plugin fields IDs */ diff --git a/site/helpers/componentbuilder.php b/site/helpers/componentbuilder.php index fb6062b96..b5e0291dc 100644 --- a/site/helpers/componentbuilder.php +++ b/site/helpers/componentbuilder.php @@ -6622,7 +6622,22 @@ abstract class ComponentbuilderHelper return array_values($fieldIds); } return false; - } + } + + + /** + * create plugin class name + */ + public static function createPluginClassName($group, $code_name) + { + // editors-xtd group plugins must have a class with plgButton structure + if ($group == 'editors-xtd') + $group= 'Button'; + + return 'Plg' . ucfirst($group) . ucfirst( + $code_name + ); + } /** * get an admin view fields IDs -- 2.40.1