@@ -105,7 +105,7 @@ public function import($data)
105105 $ fields = array (
106106 // column => data type (see settype())
107107 'rule_id ' => 'integer ' ,
108- 'rule_language ' => 'integer ' ,
108+ 'rule_language ' => 'string ' ,
109109 'rule_left_id ' => 'integer ' ,
110110 'rule_right_id ' => 'integer ' ,
111111 'rule_parent_id ' => 'integer ' ,
@@ -149,9 +149,9 @@ public function import($data)
149149 // Some fields must be unsigned (>= 0)
150150 $ validate_unsigned = array (
151151 'rule_id ' ,
152- 'rule_language ' ,
153152 'rule_left_id ' ,
154153 'rule_right_id ' ,
154+ 'rule_parent_id ' ,
155155 'rule_message_bbcode_options ' ,
156156 );
157157
@@ -172,12 +172,12 @@ public function import($data)
172172 *
173173 * Will throw an exception if the rule was already inserted (call save() instead)
174174 *
175- * @param int $language The language identifier
175+ * @param string $language The language iso
176176 * @return rule_interface $this object for chaining calls; load()->set()->save()
177177 * @access public
178178 * @throws \phpbb\boardrules\exception\out_of_bounds
179179 */
180- public function insert ($ language = 0 )
180+ public function insert ($ language )
181181 {
182182 if (!empty ($ this ->data ['rule_id ' ]))
183183 {
@@ -501,7 +501,7 @@ public function set_anchor($anchor)
501501 FROM ' . $ this ->boardrules_table . "
502502 WHERE rule_anchor = ' " . $ this ->db ->sql_escape ($ anchor ) . "'
503503 AND rule_id <> " . $ this ->get_id () .
504- ($ this ->get_language () ? ' AND rule_language = ' . $ this ->get_language () : '' );
504+ ($ this ->get_language () ? " AND rule_language = ' " . $ this ->get_language () . " ' " : '' );
505505 $ result = $ this ->db ->sql_query_limit ($ sql , 1 );
506506 $ row = $ this ->db ->sql_fetchrow ($ result );
507507 $ this ->db ->sql_freeresult ($ result );
@@ -519,28 +519,45 @@ public function set_anchor($anchor)
519519 }
520520
521521 /**
522- * Get the language identifier
522+ * Get the language iso
523523 *
524- * @return int language identifier
524+ * @return string language iso
525525 * @access public
526526 */
527527 public function get_language ()
528528 {
529- return isset ($ this ->data ['rule_language ' ]) ? ( int ) $ this ->data ['rule_language ' ] : 0 ;
529+ return isset ($ this ->data ['rule_language ' ]) ? $ this ->data ['rule_language ' ] : '' ;
530530 }
531531
532532 /**
533- * Set the language identifier
533+ * Set the language iso
534534 *
535- * @param int $language language identifier
535+ * @param string $language language iso
536536 * @return rule_interface $this object for chaining calls; load()->set()->save()
537537 * @access public
538+ * @throws \phpbb\boardrules\exception\unexpected_value
538539 */
539540 public function set_language ($ language )
540541 {
541542 if (!isset ($ this ->data ['rule_language ' ]))
542543 {
543- $ this ->data ['rule_language ' ] = (int ) $ language ;
544+ // Validate the requested language ISO is installed
545+ if ($ language !== '' )
546+ {
547+ $ sql = 'SELECT lang_id
548+ FROM ' . LANG_TABLE . "
549+ WHERE lang_iso = ' " . $ this ->db ->sql_escape ($ language ) . "' " ;
550+ $ result = $ this ->db ->sql_query ($ sql );
551+ $ lang_id = $ this ->db ->sql_fetchfield ('lang_id ' );
552+ $ this ->db ->sql_freeresult ($ result );
553+
554+ if (!$ lang_id )
555+ {
556+ throw new \phpbb \boardrules \exception \unexpected_value (array ('rule_language ' , 'WRONG_DATA_LANG ' , 'UNEXPECTED_VALUE ' ));
557+ }
558+ }
559+
560+ $ this ->data ['rule_language ' ] = $ language ;
544561 }
545562
546563 return $ this ;
0 commit comments