MyBB Community Forums

Full Version: Insertion Issues with YourCode
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I know that Wildcard discontinued support for this Plugin ages ago, and my initial course of action was to see if anyone was game for a replacement, but after nearly a week without response to the matter I've come to the conclusion that I was too hasty to abandon the notion of just fixing what's broken.

Through the power of error logging, I've figured out that the problem seems to be boolean properties that are initially set as "false" are instead fed into the database insertion query's array as Null values that are then rejected at insertion time. I also have a general window of when it happens in both major cases it's come up (making new YourCodes and porting old MyCodes on plugin install, in both cases likely prior to entry #4 of the backtrace), but thanks to my limited understanding of PHP I've hit a wall in diagnosing the actual discrepancy in the code.

For two examples of this happening, here is a quick snippet of two separate incidents from my Error Logs, with the root directory censored to "{$mybb->settings['bburl']}" to protect private information as this is a local install of myBB.

Case #1: Installing the YourCode plugin. The error occurs when the installation attempts to convert existing MyCodes to YourCodes.
<error>
<dateline>1709168682</dateline>
<script></script>
<line>0</line>
<type>20</type>
<friendly_type>MyBB SQL Error</friendly_type>
<message>SQL Error: 1366 - Incorrect integer value: '' for column 'nestable' at row 1
Query:
INSERT
INTO mybb_yourcode (`title`,`description`,`parse_order`,`nestable`,`active`,`case_sensitive`,`single_line`,`multi_line`,`eval`,`callback`,`regex`,`replacement`,`alt_replacement`,`can_use`,`can_view`,`default_id`,`dateline`)
VALUES ('Format - Bold','MyBB Default Bold MyCode',10,'','1','','1','','','','\\[b\\](.*?)\\[/b\\]','<span style=\"font-weight: bold;\" class=\"mycode_b\">$1</span>','','','',1,1709168682)
</message>
<back_trace>#0  errorHandler->error() called at [{$mybb->settings['bburl']}\inc\db_mysqli.php:609]
#1  DB_MySQLi->error() called at [{$mybb->settings['bburl']}\inc\db_mysqli.php:345]
#2  DB_MySQLi->query() called at [{$mybb->settings['bburl']}\inc\db_mysqli.php:378]
#3  DB_MySQLi->write_query() called at [{$mybb->settings['bburl']}\inc\db_mysqli.php:843]
#4  DB_MySQLi->insert_query() called at [{$mybb->settings['bburl']}\inc\plugins\yourcode\classes\StorableObject010000.php:136]
#5  StorableObject010000->save() called at [{$mybb->settings['bburl']}\inc\plugins\yourcode\install.php:297]
#6  yourcode_port_old_mycode() called at [{$mybb->settings['bburl']}\inc\plugins\yourcode\install.php:134]
#7  yourcode_install() called at [[PHP]: ]
#8  call_user_func() called at [{$mybb->settings['bburl']}\admin\modules\config\plugins.php:432]
#9  require() called at [{$mybb->settings['bburl']}\admin\index.php:830]
</back_trace>
</error>

Case #2: Attempting to make a YourCode. Again, the makings of the error seem to lie within the same apparent FALSE to NULL problem.
<error>
<dateline>1709169542</dateline>
<script></script>
<line>0</line>
<type>20</type>
<friendly_type>MyBB SQL Error</friendly_type>
<message>SQL Error: 1366 - Incorrect integer value: '' for column 'default_id' at row 1
Query:
INSERT
INTO mybb_yourcode (`title`,`description`,`parse_order`,`nestable`,`active`,`case_sensitive`,`single_line`,`multi_line`,`eval`,`callback`,`regex`,`replacement`,`alt_replacement`,`can_use`,`can_view`,`default_id`,`dateline`)
VALUES ('Ipsum','A test of the YourCode module.','10','0','1','0','0','1','0','0','IPSUM','DOLOR','','','','',1709169542)
</message>
<back_trace>#0  errorHandler->error() called at [{$mybb->settings['bburl']}\inc\db_mysqli.php:609]
#1  DB_MySQLi->error() called at [{$mybb->settings['bburl']}\inc\db_mysqli.php:345]
#2  DB_MySQLi->query() called at [{$mybb->settings['bburl']}\inc\db_mysqli.php:378]
#3  DB_MySQLi->write_query() called at [{$mybb->settings['bburl']}\inc\db_mysqli.php:843]
#4  DB_MySQLi->insert_query() called at [{$mybb->settings['bburl']}\inc\plugins\yourcode\classes\StorableObject010000.php:136]
#5  StorableObject010000->save() called at [{$mybb->settings['bburl']}\inc\plugins\yourcode\acp.php:364]
#6  yourcode_admin_edit() called at [{$mybb->settings['bburl']}\inc\plugins\yourcode\acp.php:62]
#7  yourcode_admin() called at [{$mybb->settings['bburl']}\inc\class_plugins.php:142]
#8  pluginSystem->run_hooks() called at [{$mybb->settings['bburl']}\admin\index.php:828]
</back_trace>
</error>

Strangely, this doesn't seem to happen with booleans set to "true". Could someone a little better versed in PHP tell me where the problem is and possibly offer a solution?
maybe this thread can help you

https://community.mybb.com/thread-232681.html
(2024-03-02, 06:36 AM)PARADOX987 Wrote: [ -> ]maybe this thread can help you

https://community.mybb.com/thread-232681.html

I'm glad this thread was linked, as while I'd already made several of the edits advised in it, I'm sure it will likely prove useful to anyone else who runs into this thread while looking for answers.

That said, there was one key exception in that advice that I had neglected: I was able to follow through on every recommended edit in the thread but disabling Strict Mode. Still, I did find a workaround that allowed me to avoid doing that.

In "inc/plugins/YourCode/classes/StorableObject010000.php", I changed Line 105 to
 $this->data[$property] = (int) $value;

And in "inc\plugins\yourcode\acp.php", I changed Line 474 to
 $form_container->output_row($lang->yourcode_active, $lang->yourcode_active_desc, $form->generate_yes_no_radio('active', $data['active']) . $form->generate_hidden_field('id', $data['id']) .$form->generate_hidden_field('default_id', (int) $data['default_id']));

By using this strategy, the booleans and empty values that normally cause problems when calling the save function are instead interpreted as integers, passing the Strict SQL check and otherwise preserving natural function of the plugin. While my original focus was just eliminating blank spaces that were triggering errors a last-minute change I made even accidentally accounted for existing Default IDs brought in via the Edit YourCode feature.

At any rate, I think I can confidently say this matter is resolved. Thanks for your help, PARADOX987.

On a side-note, if a more competent programmer than myself wants to base a new fork of the Plugin on my changes, feel free. I don't dare do so myself because I don't have enough savvy to know if I broke some kind of fundamental rule of coding or forum security. I basically just sought out pressure points and then blindly beat it with a wrench until it gave up and worked.