To delete or remove a 1:1 relationship between (CRM Module) custom modules in Vtiger CRM 7 using a PHP script with vtlib functions, you need to follow these general steps:
- Load Vtiger Framework: Ensure your script includes the necessary Vtiger framework files to interact with the CRM.
- Identify Modules: Identify the custom modules involved in the relationship.
- Remove Relationship: Use the vtlib functions to remove the relationship between these modules.
Here’s a sample PHP script demonstrating how to remove a 1:1 relationship between two custom modules, CustomModule1
and CustomModule2
:
<?php
// Load Vtiger framework
require_once 'include/entryPoint.php';
require_once 'include/utils/CommonUtils.php';
require_once 'include/utils/UserInfoUtil.php';
require_once 'modules/Vtiger/CRMEntity.php';
require_once 'vtlib/Vtiger/Module.php';
// Function to remove the relationship
function removeRelationship($module1, $module2) {
global $adb;
// Get module instances
$moduleInstance1 = Vtiger_Module::getInstance($module1);
$moduleInstance2 = Vtiger_Module::getInstance($module2);
if ($moduleInstance1 && $moduleInstance2) {
// Get the relationship type between the two modules
$relationInfo = Vtiger_Relation_Model::getInstance($moduleInstance1, $moduleInstance2);
if ($relationInfo) {
// Delete the relationship
$relationInfo->delete();
echo "1:1 relationship between $module1 and $module2 has been removed successfully.";
} else {
echo "No relationship found between $module1 and $module2.";
}
} else {
echo "One or both modules not found.";
}
}
// Define your custom modules
$customModule1 = 'CustomModule1'; // Replace with your actual custom module name
$customModule2 = 'CustomModule2'; // Replace with your actual custom module name
// Remove the relationship
removeRelationship($customModule1, $customModule2);
?>
Explanation:
- Load Vtiger Framework: The
require_once
statements include necessary Vtiger files to ensure your script can interact with the Vtiger CRM framework. - Define Modules: You define the custom modules you want to work with (
CustomModule1
andCustomModule2
). Replace these placeholders with the actual module names. - Get Module Instances: Using
Vtiger_Module::getInstance()
, you get the instances of the modules. - Check Relationship: The
Vtiger_Relation_Model::getInstance()
function checks for the existing relationship between the modules. - Delete Relationship: If the relationship exists, you call the
delete()
method to remove it.
Notes:
- Ensure you have appropriate permissions and backup your CRM data before running any scripts that modify relationships.
- This script assumes that the
Vtiger_Relation_Model
class and its methods are available and that the CRM is properly configured.
Make sure to test this script in a development environment before applying it to your live CRM system to avoid any unintended consequences.
Conclusion
To simply remove or delete any 1:1 relationship between various (CRM Module) custom modules in the case of Vtiger CRM 7 with the help of a PHP script with all vtlib functions, you simply have to follow some simple steps mentioned above. Must ensure that you have the best vTiger hosting solutions.