@@ -37,6 +37,9 @@ class status extends \phpbb\notification\type\base
3737 /** @var int */
3838 protected $ ideas_forum_id ;
3939
40+ /** @var array */
41+ protected $ idea_cache = [];
42+
4043 /**
4144 * Set additional services and properties
4245 *
@@ -117,7 +120,7 @@ public function find_users_for_notification($type_data, $options = [])
117120 'ignore_users ' => [],
118121 ], $ options );
119122
120- $ idea = $ this ->idea -> get_idea ($ type_data ['idea_id ' ]);
123+ $ idea = $ this ->load_idea ($ type_data ['idea_id ' ]);
121124
122125 $ users = $ idea ? [$ idea ['idea_author ' ]] : [];
123126
@@ -195,13 +198,31 @@ public function get_email_template_variables()
195198 */
196199 public function create_insert_array ($ type_data , $ pre_create_data = [])
197200 {
198- $ idea = $ this ->idea -> get_idea ($ type_data ['idea_id ' ]);
201+ $ idea = $ this ->load_idea ($ type_data ['idea_id ' ]);
199202
200- $ this ->set_data ('idea_id ' , $ type_data ['idea_id ' ]);
201- $ this ->set_data ('status ' , $ type_data ['status ' ]);
202- $ this ->set_data ('idea_title ' , $ idea ['idea_title ' ]);
203- $ this ->set_data ('idea_author ' , $ idea ['idea_author ' ]);
203+ $ this ->set_data ('idea_id ' , ( int ) $ type_data ['idea_id ' ]);
204+ $ this ->set_data ('status ' , ( int ) $ type_data ['status ' ]);
205+ $ this ->set_data ('idea_title ' , $ idea ? $ idea ['idea_title ' ] : '' );
206+ $ this ->set_data ('idea_author ' , $ idea ? ( int ) $ idea ['idea_author ' ] : 0 );
204207
205208 parent ::create_insert_array ($ type_data , $ pre_create_data );
206209 }
210+
211+ /**
212+ * Load and cache an idea by id
213+ *
214+ * @param int $idea_id
215+ * @return array|false
216+ */
217+ protected function load_idea ($ idea_id )
218+ {
219+ $ idea_id = (int ) $ idea_id ;
220+
221+ if (!array_key_exists ($ idea_id , $ this ->idea_cache ))
222+ {
223+ $ this ->idea_cache [$ idea_id ] = $ this ->idea ->get_idea ($ idea_id ) ?: false ;
224+ }
225+
226+ return $ this ->idea_cache [$ idea_id ];
227+ }
207228}
0 commit comments