Further modularize syncing of tags with fulltext search index
This commit is contained in:
parent
cb6d0d7b06
commit
f27d0900ae
|
@ -137,17 +137,11 @@ final class NodaTagFulltextSyncManticore {
|
|||
}
|
||||
|
||||
/**
|
||||
* Runs a full sync.
|
||||
*
|
||||
* @param MDMysqli $mysqli_noda Connection to MySQL DB.
|
||||
* @param MDMysqli $mysqli_manticore Connection to Manticore DB.
|
||||
* @param string $databasename Name of the main noda database.
|
||||
* Synchronizes base entries.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function runFullSync(MDMysqli $mysqli_noda, MDMysqli $mysqli_manticore, string $databasename):void {
|
||||
|
||||
$mysqli_manticore->do_update_query_large("TRUNCATE RTINDEX `" . $databasename . "_tag`");
|
||||
public static function runFullSyncForBaseEntries(MDMysqli $mysqli_noda, MDMysqli $mysqli_manticore, string $databasename):void {
|
||||
|
||||
// Sync tags
|
||||
|
||||
|
@ -159,22 +153,24 @@ final class NodaTagFulltextSyncManticore {
|
|||
|
||||
$mysqli_manticore->autocommit(false);
|
||||
|
||||
while ($cur = $result->fetch_assoc()) {
|
||||
while ($cur = $result->fetch_row()) {
|
||||
|
||||
$tag_id = (int)$cur[0];
|
||||
|
||||
$mysqli_manticore->query("INSERT INTO `" . $databasename . "_tag`
|
||||
(`entry_id`, `language`, `name`, `description`, `timestamp`)
|
||||
VALUES
|
||||
(" . $cur['tag_id'] . ",
|
||||
(" . $tag_id . ",
|
||||
'',
|
||||
'" . $mysqli_manticore->escape_string($cur['tag_name']) . "',
|
||||
'" . $mysqli_manticore->escape_string($cur['tag_anmerkung']) . "',
|
||||
'" . strtotime($mysqli_manticore->escape_string($cur['tag_erfasst_am'])) . "')");
|
||||
'" . $mysqli_manticore->escape_string($cur[1]) . "',
|
||||
'" . $mysqli_manticore->escape_string($cur[2]) . "',
|
||||
'" . strtotime($mysqli_manticore->escape_string($cur[3])) . "')");
|
||||
|
||||
if ($mysqli_manticore->error) {
|
||||
throw new Exception($mysqli_manticore->error);
|
||||
}
|
||||
|
||||
MDConsole::write("Wrote {$cur['tag_id']}");
|
||||
MDConsole::write("Wrote #" . $tag_id);
|
||||
++$i;
|
||||
if ($i === self::FULL_SYNC_COMMIT_AFTER) {
|
||||
$mysqli_manticore->commit();
|
||||
|
@ -186,31 +182,42 @@ final class NodaTagFulltextSyncManticore {
|
|||
$result->close();
|
||||
|
||||
$mysqli_manticore->commit();
|
||||
$mysqli_manticore->autocommit(true);
|
||||
|
||||
// Sync translations
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronizes translated entries.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function runFullSyncForTranslatedEntries(MDMysqli $mysqli_noda, MDMysqli $mysqli_manticore, string $databasename):void {
|
||||
|
||||
$result = $mysqli_noda->do_read_query("SELECT `tag_id`, `trans_language`,
|
||||
`trans_name`, `trans_description`, `trans_last`
|
||||
FROM `" . $databasename . "`.`tag_translation`");
|
||||
|
||||
$mysqli_manticore->autocommit(false);
|
||||
$i = 0;
|
||||
|
||||
while ($cur = $result->fetch_assoc()) {
|
||||
while ($cur = $result->fetch_row()) {
|
||||
|
||||
$tag_id = $cur[0];
|
||||
|
||||
$mysqli_manticore->query("INSERT INTO `" . $databasename . "_tag`
|
||||
(`entry_id`, `language`, `name`, `description`, `timestamp`)
|
||||
VALUES
|
||||
(" . $cur['tag_id'] . ",
|
||||
'" . $mysqli_manticore->escape_string($cur['trans_language']) . "',
|
||||
'" . $mysqli_manticore->escape_string($cur['trans_name']) . "',
|
||||
'" . $mysqli_manticore->escape_string($cur['trans_description']) . "',
|
||||
'" . strtotime($mysqli_manticore->escape_string($cur['trans_last'])) . "')");
|
||||
(" . $tag_id . ",
|
||||
'" . $mysqli_manticore->escape_string($cur[1]) . "',
|
||||
'" . $mysqli_manticore->escape_string($cur[2]) . "',
|
||||
'" . $mysqli_manticore->escape_string($cur[3]) . "',
|
||||
'" . strtotime($mysqli_manticore->escape_string($cur[4])) . "')");
|
||||
|
||||
if ($mysqli_manticore->error) {
|
||||
throw new Exception($mysqli_manticore->error);
|
||||
}
|
||||
|
||||
MDConsole::write("Wrote {$cur['tag_id']}");
|
||||
MDConsole::write("Wrote #" . $tag_id);
|
||||
++$i;
|
||||
if ($i === self::FULL_SYNC_COMMIT_AFTER) {
|
||||
$mysqli_manticore->commit();
|
||||
|
@ -223,4 +230,25 @@ final class NodaTagFulltextSyncManticore {
|
|||
$mysqli_manticore->autocommit(true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a full sync.
|
||||
*
|
||||
* @param MDMysqli $mysqli_noda Connection to MySQL DB.
|
||||
* @param MDMysqli $mysqli_manticore Connection to Manticore DB.
|
||||
* @param string $databasename Name of the main noda database.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function runFullSync(MDMysqli $mysqli_noda, MDMysqli $mysqli_manticore, string $databasename):void {
|
||||
|
||||
$mysqli_manticore->do_update_query_large("TRUNCATE RTINDEX `" . $databasename . "_tag`");
|
||||
|
||||
self::runFullSyncForBaseEntries($mysqli_noda, $mysqli_manticore, $databasename);
|
||||
|
||||
// Sync translations
|
||||
|
||||
self::runFullSyncForTranslatedEntries($mysqli_noda, $mysqli_manticore, $databasename);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user