function end_load_data() { echo "removing data files\n"; unlink(DOC_ROOT . "temp/top_images.sql"); unlink(DOC_ROOT . "temp/top_unpublished_images.sql"); // swap temporary tables with real tables $result = $this->mysqli->query("SELECT 1 FROM top_images_tmp LIMIT 1"); if ($result && ($row = $result->fetch_assoc())) { $this->mysqli->update("RENAME TABLE top_images TO top_images_swap,\r\n top_images_tmp TO top_images,\r\n top_images_swap TO top_images_tmp"); } $result = $this->mysqli->query("SELECT 1 FROM top_unpublished_images_tmp LIMIT 1"); if ($result && ($row = $result->fetch_assoc())) { $this->mysqli->update("RENAME TABLE top_unpublished_images TO top_unpublished_images_swap,\r\n top_unpublished_images_tmp TO top_unpublished_images,\r\n top_unpublished_images_swap TO top_unpublished_images_tmp"); } $species_rank_ids = implode(",", Rank::species_ranks_ids()); // maybe also add where lft=rgt-1?? echo "top_species_images\n"; $this->mysqli->delete("DELETE FROM top_species_images"); $this->mysqli->update("INSERT INTO top_species_images (SELECT ti.* FROM hierarchy_entries he JOIN top_images ti ON (he.id=ti.hierarchy_entry_id) WHERE he.rank_id IN ({$species_rank_ids}))"); echo "top_unpublished_species_images\n"; $this->mysqli->delete("DELETE FROM top_unpublished_species_images"); $this->mysqli->update("INSERT INTO top_unpublished_species_images (SELECT tui.* FROM hierarchy_entries he JOIN top_unpublished_images tui ON (he.id=tui.hierarchy_entry_id) WHERE he.rank_id IN ({$species_rank_ids}))"); $this->mysqli->end_transaction(); }