control-cruiselines.sh

Controls import and update of cruise lines data from TravelTek XML API into WordPress.

Usage

./control-cruiselines.sh
  • Run from the scripts directory with required environment and dependencies available.
  • Optionally ensure WordPress CLI (wp), MySQL, and xmlstarlet are installed and accessible.

Steps

  1. Sets script path and sources functions.sh.
  2. Defines log file path.
  3. Prevents multiple instances (not shown in code, but referenced in comments).
  4. Removes existing cruiselines.xml.
  5. Prepares database table with control-tables.sh ff_traveltek_cruiselines.
  6. Constructs XML request for cruise lines data using credentials and API endpoint variables (ca_tt_username, ca_tt_password, ca_tt_sitename, ca_tt_language, ca_tt_endpoint).
  7. Sends request via curl and saves response to cruiselines.xml.
  8. Checks for errors in XML response (not shown in code, but referenced in comments).
  9. Renames XML attributes for consistency using xmlstarlet (id → line_id, name → line_name, ship/@name → ship_name, ship/@id → ship_id).
  10. Loads XML data into MySQL table ff_traveltek_cruiselines.
  11. Updates table with WordPress post IDs by joining on cruise_line_id meta.
  12. Removes locked cruise lines from updates (where post_lock meta is set).
  13. For cruise lines without post IDs, creates new WordPress posts (wp post create).
  14. Imports logo URL as featured image (wp media import).
  15. If WPML is active (ca_wpml), creates translations for new posts (wpml_create_translations).
  16. Calls update-cruiseline.sh to update new posts.

Variables Used

  • script_path: Path to the script directory.
  • wordpress_path: Path to WordPress installation.
  • ca_tt_username, ca_tt_password, ca_tt_sitename, ca_tt_language, ca_tt_endpoint: TravelTek API credentials and endpoint.
  • ca_db_name, ca_db_table_prefix: WordPress database name and table prefix.
  • ca_wpml: WPML plugin status.

Dependencies

  • functions.sh: Sourced for utility functions.
  • control-tables.sh: Prepares DB table.
  • update-cruiseline.sh: Updates new posts.
  • xmlstarlet: For XML attribute renaming.
  • wp CLI: For WordPress post/media operations.
  • mysql: For DB operations.

Notes

  • Removes and recreates cruiselines.xml multiple times for attribute renaming.
  • Handles locked cruise lines and WPML translations.
  • Imports logo images as featured images for new posts.