/** * Deletes orphaned files older than 1 minute (due to postponed commits, that has not been used) */ private function clearOrphanedPosts() { $deleteTimestamp = time() - self::DELETE_ORPHANED_POSTS_SECONDS; // Older than 1 minute $orphanedMenuItems = $this->database->get_col($this->database->prepare("SELECT ID FROM {$this->database->posts} AS p\n LEFT JOIN {$this->database->postmeta} AS m ON p.ID = m.post_id\n WHERE post_type = 'nav_menu_item'\n AND post_status = 'draft' AND meta_key = '_menu_item_orphaned' AND meta_value < '%d'", $deleteTimestamp)); foreach ((array) $orphanedMenuItems as $menuItemId) { wp_delete_post($menuItemId, true); $this->committer->discardPostponedCommit('menu-item-' . $menuItemId); } }
/** * Returns all ids from DB suitable for given restriction. * E.g. all comment_id values where comment_post_id = 1 * @param string $entityName * @param array $where * @return array */ private function getIdsForRestriction($entityName, $where) { $idColumnName = $this->dbSchemaInfo->getEntityInfo($entityName)->idColumnName; $table = $this->dbSchemaInfo->getPrefixedTableName($entityName); $sql = "SELECT {$idColumnName} FROM {$table} WHERE "; $sql .= join(" AND ", array_map(function ($column) { return "`{$column}` = %s"; }, array_keys($where))); $ids = $this->database->get_col($this->database->prepare($sql, $where)); return $ids; }
private function buildUpdateQueryForEntityWithNaturalVpid($updateData) { $vpid = $updateData[$this->idColumnName]; $query = "UPDATE {$this->prefixedTableName} SET"; foreach ($updateData as $key => $value) { $query .= $this->database->prepare("`{$key}` = %s,", $value); } $query[strlen($query) - 1] = ' '; // strip the last comma $query .= $this->database->prepare(" WHERE `{$this->idColumnName}` = %s", $vpid); return $query; }