Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions admin_language/en-GB/en-GB.com_tjfields.ini
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ COM_TJFIELDS_ADD_BUTTON="Add"
COM_TJFIELDS_LABEL_LANG_CONSTRAINT_ONE="Insert a language constant so that it can be used in multi language site. e.g"
COM_TJFIELDS_LABEL_LANG_CONSTRAINT_TWO=" %s_FNAME"
COM_TJFIELDS_INVALID_OPTION_VALUES="Option 'Name' or 'Value' is empty"
COM_TJFIELDS_FORM_LBL_FIELD_CURRENCY_POSITION="Currency Position"
COM_TJFIELDS_FORM_DESC_FIELD_CURRENCY_POSITION="Choose whether to show the currency symbol as a prefix or suffix."
COM_TJFIELDS_FORM_OPTION_CURRENCY_PREFIX="Prefix"
COM_TJFIELDS_FORM_OPTION_CURRENCY_SUFFIX="Suffix"
COM_TJFIELDS_FORM_LBL_FIELD_CURRENCY_SYMBOL="Currency Symbol"
COM_TJFIELDS_FORM_DESC_FIELD_CURRENCY_SYMBOL="Enter the currency symbol (e.g., ₹, $, €)."

;xml
COM_TJFIELDS_TEXT="Text"
Expand Down
115 changes: 115 additions & 0 deletions administrator/houseKeeping/1.4.6/tjVendorsColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php
/**
* @package TJ-Fields
*
* @author Techjoomla <extensions@techjoomla.com>
* @copyright Copyright (c) 2009-2021 TechJoomla. All rights reserved.
* @license GNU General Public License version 2 or later.
*/

// No direct access
defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\Table\Table;

/**
* Migration file for TJ-Fields
*
* @since 1.4.6
*/
class TjHouseKeepingTjVendorsColumn extends TjModelHouseKeeping
{
public $title = "Country, Region, and City table fix for com_tjvendors";

public $description = "Add com_tjvendors column in Country, Region, and City table";

/**
* Add com_tjvendors column in Country, Region, and City table if not exists
*
* @return void
*
* @since 1.0
*/
public function migrate()
{
$result = array();

try
{
$db = JFactory::getDbo();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Replace deprecated JFactory with Factory.

JFactory::getDbo() is deprecated in Joomla 4+. Use the modern Factory class instead.

+use Joomla\CMS\Factory;
+
-			$db = JFactory::getDbo();
+			$db = Factory::getDbo();

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In administrator/houseKeeping/1.4.6/tjVendorsColumn.php at line 39, replace the
deprecated call to JFactory::getDbo() with the modern Factory class method.
Import the Factory class if not already imported, then use Factory::getDbo() to
obtain the database object, ensuring compatibility with Joomla 4+ standards.

$query = $db->getQuery(true);
$query = "SHOW COLUMNS FROM `#__tj_city`";
$db->setQuery($query);
$columns = $db->loadAssoclist();

$columns = array_column($columns, "Field");

if (!in_array('com_tjvendors', $columns))
{
$query = "ALTER TABLE `#__tj_city` ADD COLUMN `com_tjvendors` tinyint(1) NOT NULL DEFAULT '1'";
$db->setQuery($query);

if (!$db->execute())
{
$result['status'] = false;
$result['message'] = $db->getErrorMsg();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Replace deprecated getErrorMsg() method.

getErrorMsg() is deprecated. Use modern exception handling or getErrorNum() with proper error checking.

-					$result['message']  = $db->getErrorMsg();
+					$result['message']  = 'Database error: ' . $db->getErrorNum() . ' - ' . $db->getErrorMsg();

Alternatively, consider letting database exceptions bubble up and handling them in the catch block.

Also applies to: 76-76, 97-97

🤖 Prompt for AI Agents
In administrator/houseKeeping/1.4.6/tjVendorsColumn.php at lines 55, 76, and 97,
the code uses the deprecated getErrorMsg() method to retrieve database error
messages. Replace these calls by implementing proper exception handling around
the database operations or use getErrorNum() combined with conditional checks to
detect errors. If exceptions are enabled, allow them to propagate and catch them
in a try-catch block to handle errors more robustly and replace the error
message assignment accordingly.


return $result;
}
}

$query = $db->getQuery(true);
$query = "SHOW COLUMNS FROM `#__tj_region`";
$db->setQuery($query);
$columns = $db->loadobjectlist();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix inconsistent method calls.

loadobjectlist() should be loadObjectList() (proper camelCase) to match the first usage at line 43.

-			$columns = $db->loadobjectlist();
+			$columns = $db->loadObjectList();

Apply the same fix on line 85:

-			$columns = $db->loadobjectlist();
+			$columns = $db->loadObjectList();

Also applies to: 85-85

🤖 Prompt for AI Agents
In administrator/houseKeeping/1.4.6/tjVendorsColumn.php at lines 64 and 85, the
method loadobjectlist() is incorrectly cased and should be changed to
loadObjectList() to maintain consistent camelCase usage as seen at line 43.
Update both lines to call loadObjectList() instead of loadobjectlist().


$columns = array_column($columns, "Field");

if (!in_array('com_tjvendors', $columns))
{
$query = "ALTER TABLE `#__tj_region` ADD COLUMN `com_tjvendors` tinyint(1) NOT NULL DEFAULT '1'";
$db->setQuery($query);

if (!$db->execute())
{
$result['status'] = false;
$result['message'] = $db->getErrorMsg();

return $result;
}
}

$query = $db->getQuery(true);
$query = "SHOW COLUMNS FROM `#__tj_country`";
$db->setQuery($query);
$columns = $db->loadobjectlist();

$columns = array_column($columns, "Field");

if (!in_array('com_tjvendors', $columns))
{
$query = "ALTER TABLE `#__tj_country` ADD COLUMN `com_tjvendors` tinyint(1) NOT NULL DEFAULT '1'";
$db->setQuery($query);

if (!$db->execute())
{
$result['status'] = false;
$result['message'] = $db->getErrorMsg();

return $result;
}
}
Comment on lines +37 to +101
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Reduce code duplication with helper method.

The same logic is repeated three times for different tables. Extract this into a reusable method to follow DRY principles.

+	/**
+	 * Add com_tjvendors column to a table if it doesn't exist
+	 *
+	 * @param   string  $tableName  The table name
+	 * @param   object  $db        Database object
+	 *
+	 * @return  array  Result array with status and message
+	 *
+	 * @since   1.4.6
+	 */
+	private function addColumnToTable($tableName, $db)
+	{
+		$query = "SHOW COLUMNS FROM `#__tj_{$tableName}`";
+		$db->setQuery($query);
+		$columns = $db->loadObjectList();
+		$columns = array_column($columns, "Field");
+
+		if (!in_array('com_tjvendors', $columns))
+		{
+			$query = "ALTER TABLE `#__tj_{$tableName}` ADD COLUMN `com_tjvendors` tinyint(1) NOT NULL DEFAULT '1'";
+			$db->setQuery($query);
+
+			if (!$db->execute())
+			{
+				return array(
+					'status' => false,
+					'message' => 'Database error: ' . $db->getErrorNum() . ' - ' . $db->getErrorMsg()
+				);
+			}
+		}
+
+		return array('status' => true);
+	}

Then simplify the migrate method:

 	public function migrate()
 	{
-		$result = array();
-
 		try
 		{
 			$db = Factory::getDbo();
-			$query = $db->getQuery(true);
-			$query = "SHOW COLUMNS FROM `#__tj_city`";
-			$db->setQuery($query);
-			$columns = $db->loadAssoclist();
-
-			$columns = array_column($columns, "Field");
-
-			if (!in_array('com_tjvendors', $columns))
-			{
-				$query = "ALTER TABLE `#__tj_city` ADD COLUMN `com_tjvendors` tinyint(1) NOT NULL DEFAULT '1'";
-				$db->setQuery($query);
-
-				if (!$db->execute())
-				{
-					$result['status']   = false;
-					$result['message']  = $db->getErrorMsg();
-
-					return $result;
-				}
-			}
-
-			// Similar code blocks for region and country...
+			
+			$tables = ['city', 'region', 'country'];
+			
+			foreach ($tables as $table)
+			{
+				$result = $this->addColumnToTable($table, $db);
+				
+				if (!$result['status'])
+				{
+					return $result;
+				}
+			}

-			$result['status']   = true;
-			$result['message']  = "Migration successful";
+			return array(
+				'status' => true,
+				'message' => 'Migration successful'
+			);
 		}
 		catch (Exception $e)
 		{
-			$result['err_code'] = '';
-			$result['status']   = false;
-			$result['message']  = $e->getMessage();
+			return array(
+				'err_code' => '',
+				'status' => false,
+				'message' => $e->getMessage()
+			);
 		}
-
-		return $result;
 	}

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In administrator/houseKeeping/1.4.6/tjVendorsColumn.php between lines 37 and
101, the code repeats the same logic for checking and adding the 'com_tjvendors'
column on three different tables. To fix this, create a helper method that
accepts a table name, checks if the column exists, and adds it if missing. Then
replace the repeated blocks with calls to this helper method for each table,
reducing duplication and improving maintainability.


$result['status'] = true;
$result['message'] = "Migration successful";
}
catch (Exception $e)
{
$result['err_code'] = '';
$result['status'] = false;
$result['message'] = $e->getMessage();
}

return $result;
}
}
5 changes: 5 additions & 0 deletions administrator/models/forms/types/forms/number.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
<field name="min" type="number" label="COM_TJFIELDS_FORM_LBL_FIELD_MIN" description="COM_TJFIELDS_FORM_DESC_FIELD_MIN"/>
<field name="max" type="number" label="COM_TJFIELDS_FORM_LBL_FIELD_MAX" description="COM_TJFIELDS_FORM_DESC_FIELD_MAX"/>
<field name="step" type="number" label="COM_TJFIELDS_FORM_LBL_FIELD_STEP" description="COM_TJFIELDS_FORM_DESC_FIELD_STEP"/>
<field name="data-currency-symbol" type="text" label="COM_TJFIELDS_FORM_LBL_FIELD_CURRENCY_SYMBOL" description="COM_TJFIELDS_FORM_DESC_FIELD_CURRENCY_SYMBOL"/>
<field name="data-currency-position" type="radio" label="COM_TJFIELDS_FORM_LBL_FIELD_CURRENCY_POSITION" description="COM_TJFIELDS_FORM_DESC_FIELD_CURRENCY_POSITION" class="btn-group">
<option value="prefix">COM_TJFIELDS_FORM_OPTION_CURRENCY_PREFIX</option>
<option value="suffix">COM_TJFIELDS_FORM_OPTION_CURRENCY_SUFFIX</option>
</field>
<field name="hint" type="text" label="COM_TJFIELDS_FORM_LBL_NUMBER_FIELD_PLACEHOLDER" description="COM_TJFIELDS_FORM_DESC_NUMBER_FIELD_PLACEHOLDER"/>
<field name="filter" type="text" default="number"/>
<field name="compare" type="radio" default="0" class="btn-group" label="COM_TJFIELDS_FORM_LBL_NUMBER_FIELD_COMPARE" description="COM_TJFIELDS_FORM_DESC_NUMBER_FIELD_COMPARE">
Expand Down