// Some databases or systems use GMT or UTC, so we need to // get the correct date time format at this point $UTC = new DateTimeZone("UTC"); $dateTime = new DateTime($date, $UTC);
// Set your preferred time zone $dateTime->setTimezone(new DateTimeZone('America/Los Angeles'));
// Extra: Format your date time
$dateTimeFormatted = $dateTime->format('Y-m-d H:i:s');
echo $dateTimeFormatted;
Thursday, May 25, 2017
PHP: Set Datetime with a Specific Time Zone
Friday, May 5, 2017
LINUX: Copying and Overwriting Files from a Folder to Parent Folder
cp -fR /source/files /dest
https://superuser.com/questions/358843/
how-to-replace-all-the-contents-from-one-folder-with-another-one
LINUX: Changing Group and Ownership
Note: You may need root/sudo permissions
Group:
> chgrp <group name> <directory or file name>
Owner:
> chown <user name> <directory>
Owner and Group:
> chown <user name>:<group name> <directory>
Owner and Group of all files and subfolders
> chown -R <user name>:<group name> <directory>
Group:
> chgrp <group name> <directory or file name>
Owner:
> chown <user name> <directory>
Owner and Group:
> chown <user name>:<group name> <directory>
Owner and Group of all files and subfolders
> chown -R <user name>:<group name> <directory>
Thursday, May 4, 2017
BACKBONE: Detecting Events for Several Elements
Problem:
Suppose you have several "select" elements in a table with the same data that triggers another "select" element, but you want to detect each "select" individually.
Solution:
In Backbone, we can add the "data-id" tag to the select element and dynamically populate the id in Backbone. Also, we need to add a class tag so all the "select" elements are fired without the need to construct a map or array of events. In the event you want to favor performance over simplicity, please consider the events collection approach.
Suppose you have several "select" elements in a table with the same data that triggers another "select" element, but you want to detect each "select" individually.
<table> <tr> <td><select>.....</select></td> <!--Select we want to detect--> <td><select>.....</select></td> <!--Dependent Select--> </tr> <tr> <td><select>.....</select></td> <!--Another Select--> <td><select>.....</select></td> <!--Another dependent Select--> </tr></table>
Solution:
In Backbone, we can add the "data-id" tag to the select element and dynamically populate the id in Backbone. Also, we need to add a class tag so all the "select" elements are fired without the need to construct a map or array of events. In the event you want to favor performance over simplicity, please consider the events collection approach.
({
selectTable1:
{
selectCounter : 0
},
initialize: function()
{
// Add selects dynamically here (or create a helper function),
// or get other selects, etc.
},
events:
{
'change .myClass': 'detectEvent'
},
detectEvent: function(e)
{
e.preventDefault();
var id = $(e.currentTarget).data("id");
}
)}
Tuesday, May 2, 2017
SUGARCRM: Installation Error. Config File Screen Stops Responding
Problem:
When installing SugarCRM (in my case 7.8.2.0) I got the following error in my developer console using Chrome: "document.getElementById('button_next2') undefined" and my installation stops responding while configuring my config.php file
Solution:
On my previous screen, I used an existing database. Deleting (dropping) the database and letting sugar create a new one fixed the issue. Really?
When installing SugarCRM (in my case 7.8.2.0) I got the following error in my developer console using Chrome: "document.getElementById('button_next2') undefined" and my installation stops responding while configuring my config.php file
Solution:
On my previous screen, I used an existing database. Deleting (dropping) the database and letting sugar create a new one fixed the issue. Really?
SUGARCRM: Accessing Related Beans of a Module
if($bean->load_relationship('my_relationship_name_in_studio')) { $relatedBeans = $bean->my_relationship_name_in_studio->getBeans(); } // traverse $relatedBeans here .........
SUGARCRM: Accessing Beans Inside Entry Points
Problem:
Cannot access bean data inside a custom Entry Point, and no errors are reported by either PHP or SugarCRM (i.e. empty bean array or empty bean relationships)
Solution:
Warning: This implies a security risk as anyone can access the bean now.
Cannot access bean data inside a custom Entry Point, and no errors are reported by either PHP or SugarCRM (i.e. empty bean array or empty bean relationships)
Solution:
Warning: This implies a security risk as anyone can access the bean now.
if (empty($current_user) || empty($current_user->id)) {
$current_user = new User();
$current_user->getSystemUser(); // or any other user bean
}
SUGARCRM: Error Installing SugarCRM 7.8
Problem:
Test for .htaccess rewrites failed. This usually means you do not have AllowOverride set up for Sugar directory.
Solution:
Make sure the url is being accessed via https and not http. If this does not work, add AllowOverrideAll to your config file or .htaccess under <Directory>
Test for .htaccess rewrites failed. This usually means you do not have AllowOverride set up for Sugar directory.
Solution:
Make sure the url is being accessed via https and not http. If this does not work, add AllowOverrideAll to your config file or .htaccess under <Directory>
Wednesday, April 26, 2017
PHP: Formatting Date Specified as YYYY-MM-DDT00:00:00
public function formatDate($date, $daysToAdd) { $dateTime = new DateTime($date); // Change the format accordingly $dateTimeFormatted = $dateTime->format('Y-m-d h:m:s'); return str_replace(' ', 'T', $dateTimeFormatted); }
JavaScript: Constructing a Simple JSON Object Dynamically
1. Create an initial JSON object with a single element and an array: // {$id} is a PHP variable but it can be anything else jsonObj = {"id" : "{$id}", "myArray": []}; 2. Construct the JSON object item = {} item ["id"] = "some Id"; item ["value"] = "Some Value"; jsonObj.myArray.push(item); 3. Output JavaScript: Object {id: "564f48ba-e9d5-463a-2325-58f91c653aa8", myArray: Array(1)} where myArray is broken down as follows: myArray: Array(3) 0: Object id: "Some Id", value: "Some Value" 4. Output PHP: Array ( [id] => 564f48ba-e9d5-463a-2325-58f91c653aa8 [myArray] => Array ( [0] => Array ( [id] => Some Id [value] => Some Value ) ) )
Tuesday, April 25, 2017
Friday, April 21, 2017
SUGARCRM: Querying Results using Raw SQL Statements
$sql = "SELECT id FROM accounts WHERE deleted = 0";
$result = $GLOBALS['db']->query($sql);
while($row = $GLOBALS['db']->fetchByAssoc($result) )
{
//Use $row['id'] to grab the id fields value
$id = $row['id'];
}
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.8/Data_Framework/Database/DBManagerFactory/
SUGARCRM: Getting blank Page on Entry Point
Make sure your Entry point is registered in your instance:
/custom/Extension/application/Ext/EntryPointRegistry/<your entry point>
/custom/Extension/application/Ext/EntryPointRegistry/<your entry point>
Thursday, April 20, 2017
SUGARCRM 7.8: Obtaining Field Labels based on Module Names
require_once('include/utils.php');
$label = translate('LBL_KEY', 'Accounts');
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.8/Architecture/Languages/Module_Labels/index.html
Wednesday, March 15, 2017
ELASTICSEARCH: Restarting Elastic Search SugarCRM Installation
Error:
Unable to connect to Full Text Search server, please verify settings
Solution:
1. Check ElasticSearch is running
> sudo /etc/init.d/elasticsearch status
2. If status is not running, restart
> sudo /etc/init.d/elasticsearch restart
3. If the above does not work, modify /etc/elasticsearch/elasticsearch.yml as follows:
discovery.zen.ping.multicast.enabled: false and repeat 1 & 2
Unable to connect to Full Text Search server, please verify settings
Solution:
1. Check ElasticSearch is running
> sudo /etc/init.d/elasticsearch status
2. If status is not running, restart
> sudo /etc/init.d/elasticsearch restart
3. If the above does not work, modify /etc/elasticsearch/elasticsearch.yml as follows:
discovery.zen.ping.multicast.enabled: false and repeat 1 & 2
Monday, March 6, 2017
SUGARCRM: Debugging SugarCRM 7.x
Inside a Logic Hook or any other backend file:
echo "<pre> DEBUGGING: ".PRINT_R('BEFORE' ,TRUE)."</pre>";
NOTE: The above command is for debugging purposes only. Make sure to remove that command before pushing to either production or QA.
echo "<pre> DEBUGGING: ".PRINT_R('BEFORE' ,TRUE)."</pre>";
NOTE: The above command is for debugging purposes only. Make sure to remove that command before pushing to either production or QA.
SUGARCRM: 500 Error when using $GLOBAL['log']->fatal()
Error: HTTP Error: 500 when saving a record.
Code: Logic hook makes a SOAP call, and then we display the result as follows:
$GLOBALS['log']->fatal('>>>>>' . $response, true); // ERROR HERE
Solution:
$response is returning a JSON object, so we need to escape the result as follows:
$GLOBALS['log']->fatal('>>>>>' . print_r($response, true));
Code: Logic hook makes a SOAP call, and then we display the result as follows:
$GLOBALS['log']->fatal('>>>>>' . $response, true); // ERROR HERE
Solution:
$response is returning a JSON object, so we need to escape the result as follows:
$GLOBALS['log']->fatal('>>>>>' . print_r($response, true));
Friday, February 3, 2017
SALESFORCE: Split Types
Error:
Validation Errors While Saving Record(s) There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "You do not have sufficient access to modify splits of this split type.
Solution:
Verify which fields are being used under Opportunity Split and set the correct permissions on that field.
1. Go to Setup->Customize->Opportunities->Opportunity Split->Settings
2. Check which fields are set to split
3. Go to the Opportunity object and set the correct security permissions for those fields
Validation Errors While Saving Record(s) There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "You do not have sufficient access to modify splits of this split type.
Solution:
Verify which fields are being used under Opportunity Split and set the correct permissions on that field.
1. Go to Setup->Customize->Opportunities->Opportunity Split->Settings
2. Check which fields are set to split
3. Go to the Opportunity object and set the correct security permissions for those fields
SALESFORCE: Permission Issues
Error:
"INVALID_FIELD: Select Id, Name from User Where ProfileId in ('') AND UserRoleId ^ ERROR at Row:1:Column:33 No such column 'ProfileId' on entity 'User'. If you are attempting to use a custom field,
be sure to append the '__c' after the custom field name. Please reference your WSDL or
the describe call for the appropriate names."
Solution:
Go to the Profile having the issue, and make sure "View Setup and Configuration" option is checked.
Monday, January 30, 2017
SUGARCRM: Package Deployment
Problem:
You get the following error when trying to deploy a new package from Admin:
"An error has occurred during deploying process, your package may not have installed correctly."
Analyzing the logs, we get:
[FATAL] ERROR: rmdir_recursive(): argument is not a file or a dir.
Solution:
Open config.php and make sure both group and user are set to the correct values.
array (
'dir_mode' => 493,
'file_mode' => 493,
'user' => '',
'group' => '',
),
You get the following error when trying to deploy a new package from Admin:
"An error has occurred during deploying process, your package may not have installed correctly."
Analyzing the logs, we get:
[FATAL] ERROR: rmdir_recursive(): argument is not a file or a dir.
Solution:
Open config.php and make sure both group and user are set to the correct values.
array (
'dir_mode' => 493,
'file_mode' => 493,
'user' => '',
'group' => '',
),
Subscribe to:
Posts (Atom)