Cacti / cacti

Cacti ™
http://www.cacti.net
GNU General Public License v2.0
1.64k stars 405 forks source link

sqltable_to_php.php does not always generate valid table data arrays #2702

Closed ddb4github closed 5 years ago

ddb4github commented 5 years ago

Describe the bug db_update_table function does not support table data array that is generated by sqltable_to_php.php with args '--plugin' and '--update'

Expected behavior sqltable_to_php.php always output primary key as below if '--update' is specified: $data['primary'] = 'host,graph';

cigamit commented 5 years ago

Should be resolved.

ddb4github commented 5 years ago

Should be resolved.

After review my message. I found I make misleading between "Describe the bug" and "Expected behavior".

Actually, current function 'db_update_table' use 'array_diff' to compare PK. so sqltable_to_php.php should always output a array if the latest line of output is db_update_table, like

db_update_table ('plugin_mikrotik_users', $data, false);

So suggest diff as below, base on ad50326:

--- sqltable_to_php.php 2019-05-25 19:42:53.000000000 +0800
+++ sqltable_to_php.php 2019-05-28 13:22:50.264353736 +0800
@@ -155,7 +155,7 @@
                        }

                        if (!empty($pri)) {
-                               if ($plugin != '' || !$create) {
+                               if ($plugin != '' && $create) {
                                        $text .= "\$data['primary'] = '" . implode("`,`", $pri) . "';\n";
                                } else {
                                        $text .= "\$data['primary'] = array('" . implode("','", $pri) . "');\n";
cigamit commented 5 years ago

Okay, fixed up.