@@ -245,52 +245,6 @@ public function save_translation( \WP_REST_Request $request ) {
245245 return $ output ;
246246 }
247247
248- /**
249- * A slightly modified version og GP_Original->by_project_id_and_entry without the BINARY search keyword
250- * to make sure the index on the gp_originals table is used
251- *
252- * @param int $project_id The project id.
253- * @param object $entry The entry.
254- * @param string $status The status.
255- *
256- * @return array|null The original entry.
257- */
258- private function by_project_id_and_entry ( $ project_id , $ entry , $ status = '+active ' ) {
259- global $ wpdb ;
260-
261- $ entry ->plural = isset ( $ entry ->plural ) ? $ entry ->plural : null ;
262- $ entry ->context = isset ( $ entry ->context ) ? $ entry ->context : null ;
263-
264- $ where = array ();
265-
266- $ where [] = is_null ( $ entry ->context ) ? '(context IS NULL OR %s IS NULL) ' : 'context = %s ' ;
267- $ where [] = 'singular = %s ' ;
268- $ where [] = is_null ( $ entry ->plural ) ? '(plural IS NULL OR %s IS NULL) ' : 'plural = %s ' ;
269- $ where [] = 'project_id = %d ' ;
270- $ where [] = $ wpdb ->prepare ( 'status = %s ' , $ status );
271-
272- $ where = implode ( ' AND ' , $ where );
273-
274- $ query = "SELECT * FROM $ wpdb ->gp_originals WHERE $ where " ;
275- $ result = GP ::$ original ->one ( $ query , $ entry ->context , $ entry ->singular , $ entry ->plural , $ project_id );
276- if ( ! $ result ) {
277- return null ;
278- }
279- // We want case sensitive matching but this can't be done with MySQL while continuing to use the index therefore we do an additional check here.
280- if ( $ result ->singular === $ entry ->singular ) {
281- return $ result ;
282- }
283-
284- // We then get the whole result set here and check each entry manually.
285- $ results = GP ::$ original ->many ( $ query . ' AND id != %d ' , $ entry ->context , $ entry ->singular , $ entry ->plural , $ project_id , $ result ->id );
286- foreach ( $ results as $ result ) {
287- if ( $ result ->singular === $ entry ->singular ) {
288- return $ result ;
289- }
290- }
291-
292- return null ;
293- }
294248 /**
295249 * Gets translations by title.
296250 *
@@ -379,7 +333,7 @@ public function get_translations_by_originals( \WP_REST_Request $request ) {
379333 $ checked_originals [ $ key ] = true ;
380334
381335 foreach ( $ translation_sets [ $ text_domain ] as $ project_id => $ translation_set ) {
382- $ original_record = $ this -> by_project_id_and_entry ( $ project_id , $ original );
336+ $ original_record = GP_Original:: by_project_id_and_entry ( $ project_id , $ original );
383337 if ( ! $ original_record ) {
384338 continue ;
385339 }
0 commit comments