Code Duplication    Length = 23-27 lines in 2 locations

main/inc/lib/link.lib.php 1 location

@@ 448-474 (lines=27) @@
445
     * @param int $link_id Document id to delete
446
     * @return void
447
     */
448
    public static function delete_link_from_search_engine($course_id, $link_id)
449
    {
450
        // Remove from search engine if enabled.
451
        if (api_get_setting('search_enabled') == 'true') {
452
            $tbl_se_ref = Database:: get_main_table(
453
                TABLE_MAIN_SEARCH_ENGINE_REF
454
            );
455
            $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s LIMIT 1';
456
            $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_LINK, $link_id);
457
            $res = Database:: query($sql);
458
            if (Database:: num_rows($res) > 0) {
459
                $row = Database:: fetch_array($res);
460
                require_once api_get_path(
461
                        LIBRARY_PATH
462
                    ) . 'search/ChamiloIndexer.class.php';
463
                $di = new ChamiloIndexer();
464
                $di->remove_document((int)$row['search_did']);
465
            }
466
            $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s LIMIT 1';
467
            $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_LINK, $link_id);
468
            Database:: query($sql);
469
470
            // Remove terms from db.
471
            require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
472
            delete_all_values_for_item($course_id, TOOL_DOCUMENT, $link_id);
473
        }
474
    }
475
476
    /**
477
     *

main/inc/lib/document.lib.php 1 location

@@ 1301-1323 (lines=23) @@
1298
     * @param string $course_id Course code
1299
     * @param int $document_id Document id to delete
1300
     */
1301
    public static function delete_document_from_search_engine($course_id, $document_id)
1302
    {
1303
        // remove from search engine if enabled
1304
        if (api_get_setting('search_enabled') == 'true') {
1305
            $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
1306
            $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s LIMIT 1';
1307
            $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_DOCUMENT, $document_id);
1308
            $res = Database::query($sql);
1309
            if (Database::num_rows($res) > 0) {
1310
                $row2 = Database::fetch_array($res);
1311
                require_once api_get_path(LIBRARY_PATH) . 'search/ChamiloIndexer.class.php';
1312
                $di = new ChamiloIndexer();
1313
                $di->remove_document((int) $row2['search_did']);
1314
            }
1315
            $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s LIMIT 1';
1316
            $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_DOCUMENT, $document_id);
1317
            Database::query($sql);
1318
1319
            // remove terms from db
1320
            require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
1321
            delete_all_values_for_item($course_id, TOOL_DOCUMENT, $document_id);
1322
        }
1323
    }
1324
1325
    /**
1326
     * Gets the id of a document with a given path