/** * Commits db changes if database has been locked */ private function commitDatabase() { if ($this->isDatabaseLocked) { $this->database->query("COMMIT"); $this->database->query("UNLOCK TABLES"); $this->isDatabaseLocked = false; } $this->reportProgressChange(InitializerStates::DB_WORK_DONE); }
public function prepare_deleteOrphanedMenuItems() { $dbHost = self::$testConfig->testSite->dbHost; $dbUser = self::$testConfig->testSite->dbUser; $dbPassword = self::$testConfig->testSite->dbPassword; $dbName = self::$testConfig->testSite->dbName; $wpdb = new \wpdb($dbUser, $dbPassword, $dbName, $dbHost); $wpdb->set_prefix(self::$testConfig->testSite->dbTablePrefix); $deleteOrphanedFilesSeconds = Reverter::DELETE_ORPHANED_POSTS_SECONDS; $database = new Database($wpdb); $database->query($wpdb->prepare("UPDATE {$database->postmeta} SET meta_value = meta_value - {$deleteOrphanedFilesSeconds} " . "WHERE meta_key='_menu_item_orphaned' ORDER BY meta_id DESC LIMIT 1", [])); $pluginsDir = self::$wpAutomation->getPluginsDir(); $updateConfigArgs = ['VERSIONPRESS_GUI', 'html', 'require' => $pluginsDir . '/versionpress/src/Cli/vp-internal.php']; self::$wpAutomation->runWpCliCommand('vp-internal', 'update-config', $updateConfigArgs); }
private function updateChangeDateForPosts($vpIds) { $storage = $this->storageFactory->getStorage('post'); $date = current_time('mysql'); $dateGmt = current_time('mysql', true); foreach ($vpIds as $vpId) { $post = $storage->loadEntity($vpId, null); if ($post) { $sql = "update {$this->database->prefix}posts set post_modified = '{$date}', " . "post_modified_gmt = '{$dateGmt}' where ID = (select id from {$this->database->prefix}vp_id " . "where vp_id = unhex('{$vpId}'))"; $this->database->query($sql); $post['post_modified'] = $date; $post['post_modified_gmt'] = $dateGmt; $storage->save($post); } } }
private function fixMnReferences() { $referencesToSave = $this->getExistingMnReferences(); $vpIdsToLoad = $this->getAllVpIdsUsedInReferences($referencesToSave); $idMap = $this->getIdsForVpIds($vpIdsToLoad); $hasAllIds = $this->idMapContainsAllVpIds($idMap, $vpIdsToLoad); if (!$hasAllIds) { return false; } foreach ($referencesToSave as $reference => $relations) { if ($this->entityInfo->isVirtualReference($reference)) { continue; } $referenceDetails = ReferenceUtils::getMnReferenceDetails($this->dbSchema, $this->entityName, $reference); $prefixedTable = $this->database->prefix . $referenceDetails['junction-table']; $sourceColumn = $referenceDetails['source-column']; $targetColumn = $referenceDetails['target-column']; $valuesForInsert = array_map(function ($relation) use($idMap) { $sourceId = $idMap[$relation['vp_id']]; $targetId = $idMap[$relation['referenced_vp_id']]; return "({$sourceId}, {$targetId})"; }, $relations); $sql = sprintf("SELECT id FROM %s WHERE HEX(vp_id) IN ('%s')", $this->database->vp_id, join("', '", array_map(function ($entity) { return $entity['vp_id']; }, $this->entities))); $processedIds = array_merge($this->database->get_col($sql), $this->deletedIds); if ($this->isSelectiveSynchronization) { if (count($processedIds) > 0) { $this->database->query("DELETE FROM {$prefixedTable} WHERE {$sourceColumn} IN (" . join(", ", $processedIds) . ")"); } } else { $this->database->query("TRUNCATE TABLE {$prefixedTable}"); } $valuesString = join(", ", $valuesForInsert); $insertSql = "INSERT IGNORE INTO {$prefixedTable} ({$sourceColumn}, {$targetColumn}) VALUES {$valuesString}"; $this->database->query($insertSql); } return true; }
private function saveId($entityName, $id, $vpId) { $tableName = $this->schemaInfo->getTableName($entityName); $query = "INSERT INTO {$this->database->vp_id} (`vp_id`, `table`, `id`)\n VALUES (UNHEX('{$vpId}'), \"{$tableName}\", {$id})"; $this->database->query($query); }
/** * Function used by Synchronizer - see `schema.yml`. It restores the `wp_term_taxonomy.count` column after sync. * * @param Database $database */ function vp_fix_posts_count($database) { $sql = "update {$database->term_taxonomy} tt set tt.count =\n (select count(*) from {$database->term_relationships} tr where tr.term_taxonomy_id = tt.term_taxonomy_id);"; $database->query($sql); }