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
- Sets script path and sources
functions.sh. - Defines log file path.
- Prevents multiple instances (not shown in code, but referenced in comments).
- Removes existing
cruiselines.xml. - Prepares database table with
control-tables.sh ff_traveltek_cruiselines. - 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). - Sends request via
curland saves response tocruiselines.xml. - Checks for errors in XML response (not shown in code, but referenced in comments).
- Renames XML attributes for consistency using
xmlstarlet(id → line_id, name → line_name, ship/@name → ship_name, ship/@id → ship_id). - Loads XML data into MySQL table
ff_traveltek_cruiselines. - Updates table with WordPress post IDs by joining on
cruise_line_idmeta. - Removes locked cruise lines from updates (where
post_lockmeta is set). - For cruise lines without post IDs, creates new WordPress posts (
wp post create). - Imports logo URL as featured image (
wp media import). - If WPML is active (
ca_wpml), creates translations for new posts (wpml_create_translations). - Calls
update-cruiseline.shto 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.wpCLI: For WordPress post/media operations.mysql: For DB operations.
Notes
- Removes and recreates
cruiselines.xmlmultiple times for attribute renaming. - Handles locked cruise lines and WPML translations.
- Imports logo images as featured images for new posts.