Invision Community 5: A video walkthrough creating a custom theme and homepage By Matt Thursday at 04:02 PM
Miss_B Posted September 14, 2021 Posted September 14, 2021 Hello, I have developed an app that places topics on a scheduled list to be posted at a later time. On my end everything works fine, but I have gotten a message from the MP moderator that it is throwing the following error: INSERT INTO `core_attachments_map` ( `attachment_id`, `location_key`, `id1`, `id2`, `id3`, `temp`, `lang` ) VALUES ( 1, 'scheduledtopics_scheduledtopics', NULL, 'scheduledtopics', NULL, array ( 0 => NULL, 1 => 'scheduledtopics', ), NULL ) ON DUPLICATE KEY UPDATE `attachment_id`=VALUES(`attachment_id`), `location_key`=VALUES(`location_key`), `id1`=VALUES(`id1`), `id2`=VALUES(`id2`), `id3`=VALUES(`id3`), `temp`=VALUES(`temp`), `lang`=VALUES(`lang`) IPS\Db\Exception: Incorrect integer value: 'scheduledtopics' for column 'id2' at row 1 (1366) As mentioned, I can not reproduce this myself. And the code that I am using for the editor is the same like in my other apps. This is the form for the editor: $scheduled = new \IPS\scheduledtopics\Scheduledtopics; $form = new \IPS\Helpers\Form; $form->class .= ' ipsPad'; $form->add( new \IPS\Helpers\Form\Editor( 'topic_message', NULL, TRUE, array( 'app' => 'scheduledtopics', 'key' => 'scheduledtopics', 'autoSaveKey' => 'topic_message', 'attachIds' => NULL ) ) ); if ( $values = $form->values() ) { $scheduled->topic_message = $values['topic_message']; /* Insert in the database */ $scheduled->save(); \IPS\File::claimAttachments( 'topic_message', $scheduled->id ); } Can someone please tell me is there is anything wrong with the code? I would really appreciate it.
Adriano Faria Posted September 14, 2021 Posted September 14, 2021 Check your EditorLocation extension. Miss_B 1
Miss_B Posted September 14, 2021 Author Posted September 14, 2021 3 minutes ago, Adriano Faria said: Check your EditorLocation extension. It contains the same code that I have used in my other apps. But maybe I am missing something... /** * Editor Extension: scheduledtopics */ class _scheduledtopics { /** * Can we use HTML in this editor? * * @param \IPS\Member $member The member * @return bool|null NULL will cause the default value (based on the member's permissions) to be used, and is recommended in most cases. A boolean value will override that. */ public function canUseHtml( $member ) { return NULL; } /** * Can we use attachments in this editor? * * @param \IPS\Member $member The member * @param \IPS\Helpers\Form\Editor $field The editor field * @return bool|null NULL will cause the default value (based on the member's permissions) to be used, and is recommended in most cases. A boolean value will override that. */ public function canAttach( $member, $field ) { return NULL; } /** * Permission check for attachments * * @param \IPS\Member $member The member * @param int|null $id1 Primary ID * @param int|null $id2 Secondary ID * @param string|null $id3 Arbitrary data * @param array $attachment The attachment data * @param bool $viewOnly If true, just check if the user can see the attachment rather than download it * @return bool */ public function attachmentPermissionCheck( $member, $id1, $id2, $id3, $attachment, $viewOnly=FALSE ) { /* Make sure that you add a relevant permission check to prevent attachments being accessed via ID enumeration. */ return TRUE; } /** * Attachment lookup * * @param int|null $id1 Primary ID * @param int|null $id2 Secondary ID * @param string|null $id3 Arbitrary data * @return \IPS\Http\Url|\IPS\Content|\IPS\Node\Model * @throws \LogicException */ public function attachmentLookup( $id1, $id2, $id3 ) { // return \IPS\Http\Url::internal( ... ); } /** * Rebuild attachment images in non-content item areas * * @param int|null $offset Offset to start from * @param int|null $max Maximum to parse * @return int Number completed * @note This method is optional and will only be called if it exists */ public function rebuildAttachmentImages( $offset, $max ) { return $this->performRebuild( $offset, $max, array( 'IPS\Text\Parser', 'rebuildAttachmentUrls' ) ); } /** * Rebuild content post-upgrade * * @param int|null $offset Offset to start from * @param int|null $max Maximum to parse * @return int Number completed * @note This method is optional and will only be called if it exists */ public function rebuildContent( $offset, $max ) { return $this->performRebuild( $offset, $max, array( 'IPS\Text\LegacyParser', 'parseStatic' ) ); } /** * @brief Use the cached image URL instead of the original URL */ protected $proxyUrl = FALSE; /** * Rebuild content to add or remove image proxy * * @param int|null $offset Offset to start from * @param int|null $max Maximum to parse * @param bool $proxyUrl Use the cached image URL instead of the original URL * @return int Number completed * @note This method is optional and will only be called if it exists */ public function rebuildImageProxy( $offset, $max, $proxyUrl = FALSE ) { $this->proxyUrl = $proxyUrl; return $this->performRebuild( $offset, $max, 'parseImageProxy' ); } /** * @brief Store lazy loading status ( true = enabled ) */ protected $_lazyLoadStatus = null; /** * Rebuild content to add or remove lazy loading * * @param int|null $offset Offset to start from * @param int|null $max Maximum to parse * @param bool $status Enable/Disable lazy loading * @return int Number completed * @note This method is optional and will only be called if it exists */ public function rebuildLazyLoad( $offset, $max, $status=TRUE ) { $this->_lazyLoadStatus = $status; return $this->performRebuild( $offset, $max, 'parseLazyLoad' ); } /** * Perform rebuild - abstracted as the call for rebuildContent() and rebuildAttachmentImages() is nearly identical * * @param int|null $offset Offset to start from * @param int|null $max Maximum to parse * @param callable $callback Method to call to rebuild content * @return int Number completed */ protected function performRebuild( $offset, $max, $callback ) { $did = 0; foreach( \IPS\Db::i()->select( '*', 'scheduledtopics_logs', null, 'id ASC', array( $offset, $max ) ) as $scheduled ) { $did++; try { if( $callback == 'parseImageProxy' ) { $rebuilt = \IPS\Text\Parser::removeImageProxy( $scheduled['topic_message'] ); } elseif( $callback == 'parseLazyLoad' ) { $rebuilt = \IPS\Text\Parser::parseLazyLoad( $scheduled['topic_message'], $this->_lazyLoadStatus ); } else { $rebuilt = $callback( $scheduled['topic_message'] ); } } catch( \InvalidArgumentException $e ) { if( $callback[1] == 'parseStatic' AND $e->getcode() == 103014 ) { $rebuilt = preg_replace( "#\[/?([^\]]+?)\]#", '', $scheduled['topic_message'] ); } else { throw $e; } } if( $rebuilt !== FALSE ) { \IPS\Db::i()->update( 'scheduledtopics_logs', array( 'topic_message' => $rebuilt ), array( 'id=?', $scheduled['id'] ) ); } } return $did; } /** * Total content count to be used in progress indicator * * @return int Total Count */ public function contentCount() { return \IPS\Db::i()->select( 'COUNT(*) as count', 'scheduledtopics_logs', "topic_message IS NOT NULL" )->first(); } }
Solution Adriano Faria Posted September 14, 2021 Solution Posted September 14, 2021 See the method attachmentLookup. It’s wrong. Open same extension from any other and compares to yours. Miss_B 1
Miss_B Posted September 14, 2021 Author Posted September 14, 2021 3 minutes ago, Adriano Faria said: See the method attachmentLookup. It’s wrong. Open same extension from any other and compares to yours. I see. What buffels me is that I can not reproduce the error at all. Anyways, I can return the model with this: public function attachmentLookup( $id1, $id2, $id3 ) { return \IPS\scheduledtopics\Scheduledtopics::load( $id1 ); } Will that be ok? Thank you very much for your help btw @Adriano Faria.
Adriano Faria Posted September 14, 2021 Posted September 14, 2021 1 minute ago, Miss_B said: I see. What buffels me is that I can not reproduce the error at all. Use the browser dev tools (Console) as upload is ajaxed. You will probably see the error there. 2 minutes ago, Miss_B said: Will that be ok? Probably. Attach a file and open the table in the PHPMyAdmin and see which column it updates (id1, id2 or id3). Miss_B 1
Miss_B Posted September 14, 2021 Author Posted September 14, 2021 21 minutes ago, Adriano Faria said: Use the browser dev tools (Console) as upload is ajaxed. You will probably see the error there. Probably. Attach a file and open the table in the PHPMyAdmin and see which column it updates (id1, id2 or id3). I did use the dev tools, but I could not see any errors pertaining to this. And in the other apps did not cause any errors. Anyways, I added the fix, hopefully that will fix it. Many many thanks for your time and help. It is much appreciated 😊
Recommended Posts