//item() ); } catch( \OutOfRangeException $e ){} } /** * Syncing to run when hiding * * @param \IPS\Member|NULL|FALSE $member The member doing the action (NULL for currently logged in member, FALSE for no member) * @return void */ public function onHide( $member ) { parent::onHide( $member ); static::recordSync( $this->item() ); } /** * Syncing to run when unhiding * * @param bool $approving If true, is being approved for the first time * @param \IPS\Member|NULL|FALSE $member The member doing the action (NULL for currently logged in member, FALSE for no member) * @return void */ public function onUnhide( $approving, $member ) { parent::onUnhide( $approving, $member ); static::recordSync( $this->item() ); } /** * Sync up the topic * * @param \IPS\forums\Topic $item Topic object * * @return void */ protected static function recordSync( $item ) { $synced = array(); /* We used to restrict by forum ID in these two queries, but if you move a topic to a new forum then the counts no longer sync properly */ foreach( \IPS\Db::i()->select( '*', 'cms_database_categories', array( 'category_forum_record=? AND category_forum_comments=?', 1, 1 ) ) as $category ) { try { if ( ! in_array( $category['category_database_id'], $synced ) ) { $class = '\IPS\cms\Records' . $category['category_database_id']; $object = $class::load( $item->tid, 'record_topicid' ); $object->syncRecordFromTopic( $item ); /* Successful sync (no exception thrown, so lets skip this database from now on */ $synced[] = $category['category_database_id']; } } catch( \Exception $ex ) { } } foreach( \IPS\Db::i()->select( '*', 'cms_databases', array( 'database_forum_record=? AND database_forum_comments=?', 1, 1 ) ) as $database ) { try { if ( ! in_array( $database['database_id'], $synced ) ) { $class = '\IPS\cms\Records' . $database['database_id']; $object = $class::load( $item->tid, 'record_topicid' ); $object->syncRecordFromTopic( $item ); } } catch( \Exception $ex ) { } } } }