2025-07-17 08:11:23 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# Miravia Connector - Git Deployment Script
|
|
|
|
|
# This script commits and pushes changes to the Git repository
|
|
|
|
|
|
|
|
|
|
set -e # Exit on any error
|
|
|
|
|
|
|
|
|
|
# Configuration
|
|
|
|
|
REPO_URL="https://devops.cloudhost.es/CloudHost/MiraviaConnector.git"
|
|
|
|
|
BRANCH="main"
|
|
|
|
|
PLUGIN_DIR="/home/malin/c0ding/miravia"
|
|
|
|
|
|
|
|
|
|
# Colors for output
|
|
|
|
|
RED='\033[0;31m'
|
|
|
|
|
GREEN='\033[0;32m'
|
|
|
|
|
YELLOW='\033[1;33m'
|
|
|
|
|
NC='\033[0m' # No Color
|
|
|
|
|
|
|
|
|
|
# Function to print colored output
|
|
|
|
|
print_status() {
|
|
|
|
|
echo -e "${GREEN}[INFO]${NC} $1"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print_warning() {
|
|
|
|
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print_error() {
|
|
|
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Function to check if git is installed
|
|
|
|
|
check_git() {
|
|
|
|
|
if ! command -v git &> /dev/null; then
|
|
|
|
|
print_error "Git is not installed. Please install Git first."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Function to set Git credentials
|
|
|
|
|
get_credentials() {
|
|
|
|
|
GIT_USERNAME="Malin"
|
2025-07-21 11:26:39 +02:00
|
|
|
GIT_PASSWORD="MuieSteaua09%21%40" # URL-encoded: !@ becomes %21%40
|
2025-07-17 08:11:23 +02:00
|
|
|
print_status "Using configured Git credentials..."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Function to configure Git user
|
|
|
|
|
configure_git_user() {
|
|
|
|
|
print_status "Configuring Git user..."
|
|
|
|
|
git config user.name "Miravia Connector Bot"
|
|
|
|
|
git config user.email "development@cloudhost.es"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Function to initialize git repository if needed
|
|
|
|
|
init_git_repo() {
|
|
|
|
|
if [ ! -d ".git" ]; then
|
|
|
|
|
print_status "Initializing Git repository..."
|
|
|
|
|
git init
|
|
|
|
|
git remote add origin "${REPO_URL}"
|
|
|
|
|
else
|
|
|
|
|
print_status "Git repository already initialized."
|
|
|
|
|
# Update remote URL if it changed
|
|
|
|
|
git remote set-url origin "${REPO_URL}"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Function to create .gitignore if it doesn't exist
|
|
|
|
|
create_gitignore() {
|
|
|
|
|
if [ ! -f ".gitignore" ]; then
|
|
|
|
|
print_status "Creating .gitignore file..."
|
|
|
|
|
cat > .gitignore << 'EOF'
|
|
|
|
|
# WordPress
|
|
|
|
|
wp-config.php
|
|
|
|
|
wp-content/uploads/
|
|
|
|
|
wp-content/cache/
|
|
|
|
|
wp-content/backup-db/
|
|
|
|
|
wp-content/advanced-cache.php
|
|
|
|
|
wp-content/wp-cache-config.php
|
|
|
|
|
wp-content/plugins/hello.php
|
|
|
|
|
wp-content/plugins/akismet/
|
|
|
|
|
.htaccess
|
|
|
|
|
|
|
|
|
|
# OS generated files
|
|
|
|
|
.DS_Store
|
|
|
|
|
.DS_Store?
|
|
|
|
|
._*
|
|
|
|
|
.Spotlight-V100
|
|
|
|
|
.Trashes
|
|
|
|
|
ehthumbs.db
|
|
|
|
|
Thumbs.db
|
|
|
|
|
|
|
|
|
|
# IDE files
|
|
|
|
|
.idea/
|
|
|
|
|
.vscode/
|
|
|
|
|
*.swp
|
|
|
|
|
*.swo
|
|
|
|
|
*~
|
|
|
|
|
|
|
|
|
|
# Logs
|
|
|
|
|
*.log
|
|
|
|
|
error_log
|
|
|
|
|
debug.log
|
|
|
|
|
logs/
|
|
|
|
|
|
|
|
|
|
# Temporary files
|
|
|
|
|
*.tmp
|
|
|
|
|
*.temp
|
|
|
|
|
*.bak
|
|
|
|
|
*.backup
|
|
|
|
|
|
|
|
|
|
# Node modules (if any)
|
|
|
|
|
node_modules/
|
|
|
|
|
npm-debug.log*
|
|
|
|
|
|
|
|
|
|
# Composer
|
|
|
|
|
vendor/
|
|
|
|
|
composer.lock
|
|
|
|
|
|
|
|
|
|
# Plugin specific
|
|
|
|
|
*.zip
|
|
|
|
|
data/
|
|
|
|
|
EOF
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Function to check for uncommitted changes
|
|
|
|
|
check_changes() {
|
|
|
|
|
if [ -z "$(git status --porcelain)" ]; then
|
|
|
|
|
print_warning "No changes detected. Nothing to commit."
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Function to add all changes
|
|
|
|
|
add_changes() {
|
|
|
|
|
print_status "Adding changes to staging area..."
|
|
|
|
|
git add .
|
|
|
|
|
|
|
|
|
|
# Show what will be committed
|
|
|
|
|
print_status "Files to be committed:"
|
|
|
|
|
git diff --cached --name-only
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Function to commit changes
|
|
|
|
|
commit_changes() {
|
|
|
|
|
print_status "Committing changes..."
|
|
|
|
|
|
|
|
|
|
# Create detailed commit message
|
|
|
|
|
COMMIT_MSG=$(cat << 'EOF'
|
|
|
|
|
Fix image upload structure for Miravia API compliance
|
|
|
|
|
|
|
|
|
|
🔧 Bug Fixes:
|
|
|
|
|
- Fixed product image structure to match Miravia API requirements
|
|
|
|
|
- Updated MiraviaProduct.php getData() method to wrap images in {"Image": [...]} format
|
|
|
|
|
- Updated MiraviaCombination.php getData() method to wrap SKU images properly
|
|
|
|
|
- Resolved error "[4224] The Main image of the product is required"
|
|
|
|
|
|
|
|
|
|
📋 Changes:
|
|
|
|
|
- Modified getData() methods to transform flat image arrays to nested structure
|
|
|
|
|
- Product images: images[] → Images: {"Image": [...]}
|
|
|
|
|
- SKU images: images[] → Images: {"Image": [...]}
|
|
|
|
|
- Maintains backward compatibility for empty image arrays
|
|
|
|
|
|
|
|
|
|
🎯 Impact:
|
|
|
|
|
- Product uploads will now pass Miravia's image validation
|
|
|
|
|
- Both product-level and SKU-level images properly formatted
|
|
|
|
|
- Complies with official Miravia API documentation structure
|
|
|
|
|
|
|
|
|
|
🤖 Generated with Claude Code (https://claude.ai/code)
|
|
|
|
|
|
|
|
|
|
Co-Authored-By: Claude <noreply@anthropic.com>
|
|
|
|
|
EOF
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
git commit -m "$COMMIT_MSG"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Function to push changes
|
|
|
|
|
push_changes() {
|
|
|
|
|
print_status "Pushing changes to remote repository..."
|
|
|
|
|
|
|
|
|
|
# Configure Git to use credentials
|
|
|
|
|
git config credential.helper store
|
|
|
|
|
|
|
|
|
|
# Create credentials file temporarily
|
|
|
|
|
echo "https://${GIT_USERNAME}:${GIT_PASSWORD}@devops.cloudhost.es" > ~/.git-credentials
|
|
|
|
|
|
|
|
|
|
# Push changes
|
|
|
|
|
git push -u origin $BRANCH
|
|
|
|
|
|
|
|
|
|
# Clean up credentials
|
|
|
|
|
rm -f ~/.git-credentials
|
|
|
|
|
git config --unset credential.helper
|
|
|
|
|
|
|
|
|
|
print_status "Changes pushed successfully!"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Function to show repository status
|
|
|
|
|
show_status() {
|
|
|
|
|
print_status "Repository Status:"
|
|
|
|
|
echo "Repository URL: $REPO_URL"
|
|
|
|
|
echo "Branch: $BRANCH"
|
|
|
|
|
echo "Last commit:"
|
|
|
|
|
git log -1 --oneline
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Main execution
|
|
|
|
|
main() {
|
|
|
|
|
print_status "Starting Miravia Connector Git deployment process..."
|
|
|
|
|
|
|
|
|
|
# Change to plugin directory
|
|
|
|
|
cd "$PLUGIN_DIR"
|
|
|
|
|
|
|
|
|
|
# Check prerequisites
|
|
|
|
|
check_git
|
|
|
|
|
|
|
|
|
|
# Get credentials
|
|
|
|
|
get_credentials
|
|
|
|
|
|
|
|
|
|
# Initialize and configure Git
|
|
|
|
|
init_git_repo
|
|
|
|
|
configure_git_user
|
|
|
|
|
create_gitignore
|
|
|
|
|
|
|
|
|
|
# Check for changes
|
|
|
|
|
if ! check_changes; then
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Add, commit, and push changes
|
|
|
|
|
add_changes
|
|
|
|
|
commit_changes
|
|
|
|
|
push_changes
|
|
|
|
|
|
|
|
|
|
# Show final status
|
|
|
|
|
show_status
|
|
|
|
|
|
|
|
|
|
print_status "Deployment completed successfully! 🎉"
|
|
|
|
|
print_status "You can view the changes at: $REPO_URL"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Run main function
|
|
|
|
|
main "$@"
|