Skip to content

Conversation

@Vineet7875
Copy link

@Vineet7875 Vineet7875 commented Jun 24, 2025

Summary by CodeRabbit

  • New Features
    • Added options to customize currency symbol and its position (prefix or suffix) in the user interface.
  • Chores
    • Improved database support by adding a new column for vendor management in city, region, and country records.

@coderabbitai
Copy link

coderabbitai bot commented Jun 24, 2025

Walkthrough

The changes introduce new language constants for currency formatting options in the TJFields component and add a migration script that updates three database tables by adding a new column, com_tjvendors, if it does not already exist.

Changes

File(s) Change Summary
admin_language/en-GB/en-GB.com_tjfields.ini Added language constants for currency position and symbol fields, including options and descriptions.
administrator/houseKeeping/1.4.6/tjVendorsColumn.php Introduced a migration class to add the com_tjvendors column to three tables, with error handling and status.

Sequence Diagram(s)

sequenceDiagram
    participant Admin as Administrator
    participant Migration as TjHouseKeepingTjVendorsColumn
    participant DB as Database

    Admin->>Migration: Call migrate()
    loop For each table (#__tj_city, #__tj_region, #__tj_country)
        Migration->>DB: Check if com_tjvendors column exists
        alt Column does not exist
            Migration->>DB: ALTER TABLE to add com_tjvendors
            DB-->>Migration: Success or Failure
        else Column exists
            Note over Migration: No action needed
        end
    end
    Migration-->>Admin: Return status and message
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
47.1% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (2)
administrator/houseKeeping/1.4.6/tjVendorsColumn.php (2)

29-29: Fix incorrect return type annotation.

The method actually returns an array, not void.

-	 * @return  void
+	 * @return  array

41-43: Inconsistent query building pattern.

The code inconsistently uses $db->getQuery(true) followed by string assignment. Either use the query builder properly or use direct string assignment consistently.

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

Apply similar changes for the other two table queries.

Also applies to: 62-64, 83-85

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 3952c13 and ab9ffd0.

⛔ Files ignored due to path filters (1)
  • administrator/models/forms/types/forms/number.xml is excluded by !**/*.xml
📒 Files selected for processing (2)
  • admin_language/en-GB/en-GB.com_tjfields.ini (1 hunks)
  • administrator/houseKeeping/1.4.6/tjVendorsColumn.php (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.php`: "Review the PHP code for Joomla coding standards compliance, ensuring: - Code follows Joomla's coding standards, validated using PHPCS with the Joomla standard. - Adher...

**/*.php: "Review the PHP code for Joomla coding standards compliance, ensuring:

  • Code follows Joomla's coding standards, validated using PHPCS with the Joomla standard.
  • Adherence to Joomla’s MVC structure for extensions.
  • Proper use of Joomla’s built-in functions (e.g., Input, Factory).
  • SQL queries use Joomla’s database API to prevent SQL injection.
  • Code is well-documented, with clear function and class descriptions."
  • administrator/houseKeeping/1.4.6/tjVendorsColumn.php
🔇 Additional comments (1)
admin_language/en-GB/en-GB.com_tjfields.ini (1)

209-214: LGTM! Currency formatting constants are well-structured.

The new language constants follow proper Joomla naming conventions and provide clear, descriptive text for the currency formatting functionality. The examples in the currency symbol description (₹, $, €) are helpful for users.

$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().

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.


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.

Comment on lines +37 to +101
try
{
$db = JFactory::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;
}
}

$query = $db->getQuery(true);
$query = "SHOW COLUMNS FROM `#__tj_region`";
$db->setQuery($query);
$columns = $db->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;
}
}
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants