Error encountered when creating custom field in sugarcrm - exception

I got the below warning while trying to create a custom field in sugarcrm.
Warning:
Creating default object from empty value in C:\xampp\htdocs\Sugarcrm\modules\ModuleBuilder\views\view.modulefield.php on line 151
{"east":{"title":"Edit Field","crumb":"","content":"
<\/div>\n\n

Adjust your php.ini file to set display_errors=Off
I've seen this a few times and it usually comes from code-level customization, but not always. Either way, it's the PHP Notice/Warning/Error that's throwing off the AJAX response within Studio.

This is caused by a newer version of PHP.
Add the following code after line 150 in modules/ModuleBuilder/views/view.modulefield.php
VardefManager::loadVardef($moduleName, $objectName,true);
global $dictionary;
// add the next three lines
if(!isset($module->mbvardefs) || is_null($module->mbvardefs)) {
$module->mbvardefs = new stdClass();
}
Source: https://github.com/sugarcrm/sugarcrm_dev/pull/143/files

Related

Creating classes in pimcore

I'm new to the whole pimcore thing. I am trying to play around and create classes. The issue is, I am not able to create more than 1 class, and in the database it is nameless, so when I try to create another class, it also tries to store it in the database with no name, which ends up showing an SQL error saying that there is a duplicate entry. Any ideas what the reason behind this could be?
I installed pimcore on an nginx server, I am trying to create classes by choosing Settings->Objects->Classes and then "Add Class", creating the first class was ok, I entered a name for the class and it was successfully added, however the name field in the corresponding database entry is empty, as in empty string ' '. So, when I try to add another class and pimcore attempts to store it in the table "classes", it returns an error saying that it would be a duplicate entry since they both are nameless, i.e. the name entered isn't added. The following error is what I managed to find using developer tools, could be helpful.
[WARN] Unable to parse the JSON returned by the server
minified_javascript_core_f5757da….js?_dc=3708:5684 Error: You're trying to decode an invalid JSON String:
Fatal error: Call to a member function hasChilds() on null in /var/www/html/pimproject/pimcore/modules/admin/controllers/DocumentController.php on line 59
at new Ext.Error (http://192.10.0.0/pimcore/static6/js/lib/ext/ext-all.js?_dc=3708:22:27054)
at Function.Ext.apply.raise (http://192.10.0.10/pimcore/static6/js/lib/ext/ext-all.js?_dc=3708:22:27447)
at Object.Ext.raise (http://192.10.0.10/pimcore/static6/js/lib/ext/ext-all.js?_dc=3708:22:27594)
at Object.Ext.JSON.me.decode (http://192.10.0.10/pimcore/static6/js/lib/ext/ext-all.js?_dc=3708:22:385102)
at Ext.define.onProxyLoad (http://192.10.0.10/website/var/tmp/minified_javascript_core_f5757da9fa29d5bf13e6aa5058eff9f7.js?_dc=3708:5641:28)
at Ext.cmd.derive.triggerCallbacks (http://192.10.0.10/pimcore/static6/js/lib/ext/ext-all.js?_dc=3708:22:594533)
at Ext.cmd.derive.setCompleted (http://192.10.0.10/pimcore/static6/js/lib/ext/ext-all.js?_dc=3708:22:594231)
at Ext.cmd.derive.setException (http://192.10.0.10/pimcore/static6/js/lib/ext/ext-all.js?_dc=3708:22:594444)
at Ext.cmd.derive.process (http://192.10.0.10/pimcore/static6/js/lib/ext/ext-all.js?_dc=3708:22:593638)
at Ext.cmd.derive.processResponse (http://192.10.0.10/pimcore/static6/js/lib/ext/ext-all.js?_dc=3708:22:648303)
Just reinstall Pimcore.
It can be some composer or submodules error.
I strongly recommend for the first installation to run Demo project https://github.com/pimcore/demo not Skeleton, especially if you are using Docker. Later, when you will get the feeling of Pimcore, feel free to install Skeleton or any other project.
Pimcore is stable working for years. If you had some problems before -- nowadays, it is stable.

How to resolve SQL table with prefix in PhpStorm?

I'm working on PhpStorm to develop my Prestashop websites and I can't resolve this issue. I work on localhost and successfully connected PhpStorm to my MySQL Server.
Now PhpStorm throws warnings like "unable to resolve table '${_DB_PREFIX_}cms'". Prestashop uses prefixes for table names and it seems PhpStorm can't resolve those tables with prefixes.
Is there a workaround for this ?
Here is a code exemple from Prestashop-1.6 sources :
$sql = 'SELECT c.`id_cms`, cl.`meta_title`, cl.`link_rewrite`
FROM `'._DB_PREFIX_.'cms` c
INNER JOIN `'._DB_PREFIX_.'cms_shop` cs
ON (c.`id_cms` = cs.`id_cms`)
INNER JOIN `'._DB_PREFIX_.'cms_lang` cl
ON (c.`id_cms` = cl.`id_cms`)
WHERE c.`id_cms_category` = '.(int)$id_cms_category.'
AND cs.`id_shop` = '.(int)$id_shop.'
AND cl.`id_lang` = '.(int)$id_lang.
$where_shop.'
AND c.`active` = 1
ORDER BY `position`';
The reason why this isn't work is because you are most likely only loading one schema, you need to load the information_schema.*
To do this, go to the database tab in the top right and where you have added your MySQL database right click and select properties.
Now you'll have a screen called Data Sources and Drivers, it should open on a tab called General, click the third tab called Schemas and and add information_schema.* to this list of loaded Schemas.
Click apply and okay and then PhpStorm will now know your database structure and then be intelligently able to work with you, therefor removing all the errors.
Edit: As mentioned here, this has been fixed in PhpStorm 2018.2, but only for constants.
I have a solution that doesn't involve throwing your IDE away. :)
However, a word of caution: it's an ugly hack™ that comes without guarantees.
Assuming you already have a connection to the db in PhpStorm, generate the ddl for the desired db (Right Click on the connection -> SQL Scripts -> Generate DDL to Clipboard):
Paste the content into some sql file somewhere inside your project. You should probably gitignore this file.
Replace all the tables' prefix in this ddl file with the one from your code. Use the PhpStorm typehint as a guideline. For example '._DB_PREFIX_.'cms would become ${_DB_PREFIX_}cms:
Note that you may have to use backticks to avoid breaking sql syntax due to curly brackets.
Add the ddl to your phpstorm project:
Everything should now work:
Add this comment above the $sql query.
/** #noinspection SqlResolve */
This will suppress the warning only for this statement.
For future readers, this is now supported:
https://www.jetbrains.com/help/phpstorm/2021.1/ide-advanced-metadata.html#set-up-dynamic-prefixes-for-table-names-in-sql-language-injections
.phpstorm.meta.php
<?php
namespace PHPSTORM_META {
override(
// Virtual function to indicate that all SQL
// injections will have the following replacement rules.
sql_injection_subst(),
map([
'{' => "", // all `{` in injected SQL strings will be replaced with a prefix
'}' => '', // all `}` will be replaced with an empty string
]));
}
Edit: At time of writing (2016) there was no solution to this issue. But since 2018, as mentioned in Christian's answer, you can now use constants in SQL queries.
Actually there is no way to handle that. But you may disable inspection for such warning.
Open File > Settings > Editor > Inspections
Expand SQL
Uncheck Unresolved reference

Cakephp 1.3.14 not loading database schema

We recently made some changes to our site to prepare it for pre-production:
Moved to a load-balanced architecture
Now use memcache/memcached to maintain session data
Enabled APC
Now, everything was working until we made some change that we cannot recall that has caused the database to not load schema properly. Here is an output of some debug:
Warning (512): SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 [CORE/cake/libs/model/datasources/dbo_source.php, line 684]
Query: SHOW FULL COLUMNS FROM
Warning (2): Invalid argument supplied for foreach() [APP/models/datasources/dbo/dbo_mysql.php, line 127]
Warning (2): array_keys() expects parameter 1 to be array, boolean given [CORE/cake/libs/model/datasources/dbo_source.php, line 1968]
Notice (8): Trying to get property of non-object [CORE/cake/libs/model/datasources/dbo_source.php, line 812]
Query: SHOW FULL COLUMNS FROM
Query: SHOW FULL COLUMNS FROM
Query: SHOW FULL COLUMNS FROM
Query: SHOW FULL COLUMNS FROM
Query: SHOW FULL COLUMNS FROM
Query: SHOW FULL COLUMNS FROM
As you can see, it is not loading the table names.
The other problem we noticed, is that when the query is generated, it is generated like this:
SELECT Project.id FROM AS Project WHERE 1=1
Notice that there is no table name, it simply tries to create the alias on a blank table name.
Any thoughts?
We recently made some changes to our site to prepare it for pre-production:
Thankfully you version-control your code changes and can simply roll back until you find a working version and compare to find the breaking change. With git this is easily done using git bisect.
No? Well..
Debug and identify the cause
As with any error - step one should be to look at where the error is coming from:
// cake/models/datasources/dbo/dbo_mysql.php
$cols = $this->query('SHOW FULL COLUMNS FROM ' . $this->fullTableName($model));
foreach ($cols as $column) { // #127
What should be clear here, is that Cake is unable to determine the full table name for your model.
You're trying to query a model with no table
Looking at the source for fullTableName:
// cake/libs/model/datasources/dbo_source.php
function fullTableName($model, $quote = true) {
if (is_object($model)) {
$table = $model->tablePrefix . $model->table;
} elseif (isset($this->config['prefix'])) {
$table = $this->config['prefix'] . strval($model);
} else {
$table = strval($model);
}
if ($quote) {
return $this->name($table);
}
return $table;
}
It should be clear that the model has no table according to cake.
Common causes:
The model property useTable is set to false
No describe permissions
Given the info in the question - it's most likely the first is the reason.

changing rewriteBatchedStatements with play, hibernate and mysql

I'm trying to optimize for bulk inserts via play(1.2.4)+mysql.
I saw some posts talking about adding the following to jdbc configuration (adding it to the connection string): useServerPrepStmts=false&rewriteBatchedStatements=true&useCompression=true
I've tried to do:
db=mysql://root#localhost/data?useServerPrepStmts=false&rewriteBatchedStatements=true&useCompression=true
But I get this error:
A database error occured : Cannot connected to the database, The connection property 'useCompression' only accepts values of the form: 'true', 'false', 'yes' or 'no'. The value 'true?useUnicode=yes' is not in this set.
I also tried to use db=jdbc:mysql://....
Still no luck.
What am I missing?
Play automatically appends the MySQL connection string with the following:
?useUnicode=yes&characterEncoding=UTF-8&connectionCollation=utf8_general_ci
So I am guessing your connection string ends up invalid as there is now two sets of parameters (starting with a question mark).
Unfortunately, that part of Play code is quite hard-coded in the DBPlugin class which means that you can't add the options that way. You will have to look for a way to alter the options in a later stage.

Second RMySQL operation fails - why?

I am running a script that stores different datasets to a MySQL database. This works so far, but only sequentially. e.g.:
# write table1
replaceTable(con,tbl="table1",dframe=dframe1)
# write table2
replaceTable(con,tbl="table2",dframe=dframe2)
If I select both (I use StatET / Eclipse) and run the selection, I get an error:
Error in function (classes, fdef, mtable) :
unable to find an inherited method for function "dbWriteTable",
for signature "MySQLConnection", "data.frame", "data.frame".
I guess this has to do with the fact that my con is still busy or so when the second request is started. When I run the script line after line it just works fine. Hence I wonder, how can I tell R to wait til the first request is ready and then go ahead ? How can I make R scripts interactive (just console like plot examples - no tcl/tk).
EDIT:
require(RMySQL)
replaceTable <- function(con,tbl,dframe){
if(dbExistsTable(con,tbl)){
dbRemoveTable(con,tbl)
dbWriteTable(con,tbl,dframe)
cat("Existing database table updated / overwritten.")
}
else {
dbWriteTable(con,tbl,dframe)
cat("New database table created")
}
}
dbWriteTable has two important arguments:
overwrite: a logical specifying whether to overwrite an existing table
or not. Its default is ‘FALSE’.
append: a logical specifying whether to append to an existing table
in the DBMS. Its default is ‘FALSE’.
For past project I have successfully achieve appending, overwriting, creating, ... of tables with proper combinations of these.