#!/bin/bash

# Base paths
base_path="/var/www/vhosts/weeber.ir/kaveh.moeinwp.com"
theme_source_path="$base_path/1/wp-content/themes/kavehTheme"
plugin_source_path="$base_path/1/wp-content/plugins/kaveh-core"

for i in {1..36}
do
  target_path="$base_path/$i"

  # Check if target directory exists
  if [ ! -d "$target_path" ]; then
    echo "Target path $target_path does not exist. Skipping..."
    continue
  fi

  cd "$target_path" || { echo "Failed to change directory to $target_path. Skipping..."; continue; }


  # Run WordPress CLI commands
  wp core update
  wp plugin update --all
  wp wc update
  wp elementor update db || { echo "Failed to update Elementor database for $target_path. Skipping..."; continue; }
  wp elementor flush-css || { echo "Failed to flush Elementor CSS for $target_path. Skipping..."; continue; }
  wp elementor library sync || { echo "Failed to sync Elementor library for $target_path. Skipping..."; continue; }
  wp rewrite flush || { echo "Failed to flush rewrite rules for $target_path. Skipping..."; continue; }

  echo "Successfully updated $target_path"
done
