j4upgrade script -- error correction

pastvne

Bruce Decker
Hi All, just getting back to testing.
The upgrade wiki page here: https://github.com/joomlahenk/fabrik/wiki/Upgrading-from-fabrik3.10-to-fabrik4
References this helper script to list out eval code that might need attention for the upgrade: https://skurvishenterprises.com/fabrik/downloads/j4upgrade.zip

I see a description to run via JUMI but wanted to be able to pop script into my home directory and run it. Also, in the currently published script, it references a table "#__fabrik_js_actions" but the actual name of that Fabrik table is "#__fabrik_jsactions" (note no underscore between js and actions). This is my modified script in case anyone finds it to be useful.


Code:
<?php
define( '_JEXEC', 1 );
define('JPATH_BASE', "./");
require_once JPATH_BASE . DIRECTORY_SEPARATOR . 'includes/defines.php';
require_once JPATH_BASE . DIRECTORY_SEPARATOR . 'includes/framework.php';
use Joomla\CMS\Factory;

/* Script to extract fabrik php and js for updating */
/* 2023-02-20 updated by Bruce Decker so that it can be run from root dir
     and fixes a type for "#__fabrik_jsactions". */

$doFormPhp = true;
$doListPhp = true;
$doElements = true;
$doJsActions = true;

$db = version_compare(\Joomla\CMS\Version::MAJOR_VERSION, "4", ">=") ? Factory::getContainer()->get('DatabaseDriver') : Factory::getDbo();
$query = $db->getQuery(true);

/* Get the form/list php plugin code */
$tables = ["#__fabrik_forms" => ["run" => $doFormPhp, "type" => "Form"], "#__fabrik_lists" => ["run" => $doListPhp, "type" => "List"]];
foreach ($tables as $table => $data) {
   if ($data["run"] === false) continue;
   $html = ""; $headerOutput = false;
   $query->clear()
       ->select("id, label, params")
       ->from($table);
   $db->setQuery($query);
   $rows = $db->loadAssocList();
   foreach($rows as $row) {
       $params = json_decode($row['params']);
       if (empty($params->curl_code)) continue;
       if (is_array($params->curl_code) && count($params->curl_code) == 1 && empty($params->curl_code[0])) continue;
       if (strlen($html) > 0) {
           $html .= ", ";
       } else {
           $html = "<p><strong>Fabrik ".$data['type']." plugin php: label(id)</strong></p>";
           $headerOutput = true;
       }
       $html .= $row['label']."(".$row['id'].")";
   }
   if (strlen($html) > 0) echo $html . "<br><br>";
}

if ($doElements == true) {
   $query->clear()
       ->select('`id`, `label`, `plugin`, `default`, `eval`, `params`')
       ->from("#__fabrik_elements")
       ->order("label asc");
   $db->setQuery($query);
   $rows = $db->loadAssocList();
   echo "<p><strong>Fabrik Element PHP</strong></p>";
   echo "<table class='table table-striped table-bordered' style='width:100%;'><thead>";
   echo '<tr>
           <th scope="col" style="text-align: left; width:25px;">Element Label(id)</th>
           <th scope="col" style="text-align: left; width:25px;">Plugin Type</th>
           <th scope="col" style="text-align: center; width:25px;">Eval Pop</th>
           <th scope="col" style="text-align: center; width:25px;">Eval Def</th>
           <th scope="col" style="text-align: center; width:25px;">Calc</th>
           <th scope="col" style="text-align: center; width:25px;">PHP Val</th>
           <th scope="col" style="text-align: center; width:25px;">DBJ Eval</th>
           <th scope="col" style="text-align: center; width:25px;">UPL Ren</th>';
   if ($doJsActions == true) {
       echo '<th scope="col" style="text-align: center; width:25px;">JS Code</th>';
   }
   echo '</tr></thead><tbody>';
   foreach($rows as $row) {
       $evalPop = $evalDef = $phpVal = $dbjEval = $calc = $uplRen = $jsCode = "";
       if ($row['eval'] != 0 && !empty($row['default'])) $evalDef = "X";
       if (!empty($row['fu_rename_file_code'])) $uplRen = "X";
       if (!empty($row['dropdown_populate'])) $evalPop = "X";
       if (array_key_exists('validations', $row)) {
           foreach ($row['validations'] as $key => $validation) {
               if ($validation['plugin'] != 'php') continue;
               if (array_key_exists('validation_condition', $row) && !empty($row['validation_condition']['$key'])) $phpVal = "X";
               if (array_key_exists('php-code', $row) && !empty($row['php-code']['$key'])) $phpVal = "X";
               if (!empty($phpVal)) break;
           }
       }
       $params = json_decode($row['params']);
       if (property_exists($params, 'calc_calculation') && !empty($params->calc_calculation)) $calc = "X";
       if (property_exists($params, 'dabase_join_label_eval') && !empty($params->dabase_join_label_eval)) $dbjEval = "X";
       if (property_exists($params, 'databasejoin_where_ajax_default_eval') && !empty($params->databasejoin_where_ajax_default_eval)) $dbjEval = "X";
       $query->clear()
           ->select('code')
           ->from("#__fabrik_jsactions")
           ->where("element_id=".$row['id']);
       $code = $db->loadResult();
       if (!empty($code) && gettype($code) == 'string' && $code[0] != "{") $jsCode = "X";
       if ($evalPop || $evalDef || $phpVal || $dbjEval || $calc || $uplRen || $jsCode) {
           echo '<tr>
               <th scope="row">'.$row['label'].'('.$row['id'].')</th>
               <td style="text-align: left;">'.$row['plugin'].'</td>
               <td style="text-align: center;">'.$evalPop.'</td>
               <td style="text-align: center;">'.$evalDef.'</td>
               <td style="text-align: center;">'.$calc.'</td>
               <td style="text-align: center;">'.$phpVal.'</td>
               <td style="text-align: center;">'.$dbjEval.'</td>
               <td style="text-align: center;">'.$uplRen.'</td>';
           if ($doJsActions == true) {
               echo '<td style="text-align: center;">'.$jsCode.'</td>';
           }
           echo '</tr>';

       }
   }
   echo "</tbody></table>";
}
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top