481 lines
16 KiB
PHP
481 lines
16 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Magento Category Migration Tool</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh;
|
|
padding: 20px;
|
|
}
|
|
|
|
.container {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
background: white;
|
|
border-radius: 12px;
|
|
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
|
overflow: hidden;
|
|
}
|
|
|
|
.header {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
padding: 30px;
|
|
text-align: center;
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 2.5em;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.header p {
|
|
opacity: 0.9;
|
|
font-size: 1.1em;
|
|
}
|
|
|
|
.content {
|
|
padding: 30px;
|
|
}
|
|
|
|
.section {
|
|
margin-bottom: 30px;
|
|
padding: 20px;
|
|
background: #f8f9fa;
|
|
border-radius: 8px;
|
|
border-left: 4px solid #667eea;
|
|
}
|
|
|
|
.section h2 {
|
|
color: #333;
|
|
margin-bottom: 15px;
|
|
font-size: 1.5em;
|
|
}
|
|
|
|
.connection-status {
|
|
display: flex;
|
|
gap: 20px;
|
|
margin-top: 15px;
|
|
}
|
|
|
|
.status-badge {
|
|
padding: 10px 20px;
|
|
border-radius: 6px;
|
|
font-weight: 600;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
|
|
.status-badge.success {
|
|
background: #d4edda;
|
|
color: #155724;
|
|
}
|
|
|
|
.status-badge.error {
|
|
background: #f8d7da;
|
|
color: #721c24;
|
|
}
|
|
|
|
.store-mapping {
|
|
display: grid;
|
|
grid-template-columns: 1fr auto 1fr;
|
|
gap: 15px;
|
|
align-items: center;
|
|
margin-top: 15px;
|
|
}
|
|
|
|
.store-select {
|
|
padding: 12px;
|
|
border: 2px solid #ddd;
|
|
border-radius: 6px;
|
|
font-size: 1em;
|
|
width: 100%;
|
|
background: white;
|
|
}
|
|
|
|
.store-select:focus {
|
|
outline: none;
|
|
border-color: #667eea;
|
|
}
|
|
|
|
.arrow {
|
|
font-size: 1.5em;
|
|
color: #667eea;
|
|
text-align: center;
|
|
}
|
|
|
|
.btn {
|
|
padding: 12px 30px;
|
|
border: none;
|
|
border-radius: 6px;
|
|
font-size: 1em;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: all 0.3s;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.5px;
|
|
}
|
|
|
|
.btn-primary {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
|
|
}
|
|
|
|
.btn-primary:disabled {
|
|
opacity: 0.6;
|
|
cursor: not-allowed;
|
|
transform: none;
|
|
}
|
|
|
|
.btn-secondary {
|
|
background: #6c757d;
|
|
color: white;
|
|
}
|
|
|
|
.btn-secondary:hover {
|
|
background: #5a6268;
|
|
}
|
|
|
|
.actions {
|
|
display: flex;
|
|
gap: 15px;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.log-container {
|
|
background: #1e1e1e;
|
|
color: #d4d4d4;
|
|
padding: 20px;
|
|
border-radius: 6px;
|
|
max-height: 400px;
|
|
overflow-y: auto;
|
|
font-family: 'Courier New', monospace;
|
|
font-size: 0.9em;
|
|
margin-top: 15px;
|
|
display: none;
|
|
}
|
|
|
|
.log-container.active {
|
|
display: block;
|
|
}
|
|
|
|
.log-entry {
|
|
margin-bottom: 5px;
|
|
padding: 5px 0;
|
|
}
|
|
|
|
.log-entry.error {
|
|
color: #f48771;
|
|
}
|
|
|
|
.log-entry.success {
|
|
color: #4ec9b0;
|
|
}
|
|
|
|
.info-box {
|
|
background: #e7f3ff;
|
|
border-left: 4px solid #2196F3;
|
|
padding: 15px;
|
|
border-radius: 4px;
|
|
margin-top: 15px;
|
|
}
|
|
|
|
.info-box p {
|
|
margin: 5px 0;
|
|
color: #1976D2;
|
|
}
|
|
|
|
.loading {
|
|
display: none;
|
|
text-align: center;
|
|
padding: 20px;
|
|
}
|
|
|
|
.loading.active {
|
|
display: block;
|
|
}
|
|
|
|
.spinner {
|
|
border: 4px solid #f3f3f3;
|
|
border-top: 4px solid #667eea;
|
|
border-radius: 50%;
|
|
width: 40px;
|
|
height: 40px;
|
|
animation: spin 1s linear infinite;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
@keyframes spin {
|
|
0% { transform: rotate(0deg); }
|
|
100% { transform: rotate(360deg); }
|
|
}
|
|
|
|
.stats {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
gap: 15px;
|
|
margin-top: 15px;
|
|
}
|
|
|
|
.stat-card {
|
|
background: white;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
text-align: center;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
}
|
|
|
|
.stat-card .number {
|
|
font-size: 2em;
|
|
font-weight: bold;
|
|
color: #667eea;
|
|
}
|
|
|
|
.stat-card .label {
|
|
color: #666;
|
|
margin-top: 5px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="header">
|
|
<h1>🛒 Magento Category Migration</h1>
|
|
<p>Migrate categories from Magento 1 to Magento 2 with multi-store support</p>
|
|
</div>
|
|
|
|
<div class="content">
|
|
<!-- Connection Status -->
|
|
<div class="section">
|
|
<h2>📡 Database Connections</h2>
|
|
<div class="connection-status">
|
|
<div>
|
|
<strong>Magento 1:</strong>
|
|
<span class="status-badge {{ $connectionTest['magento1'] ? 'success' : 'error' }}">
|
|
{{ $connectionTest['magento1'] ? '✓ Connected' : '✗ Failed' }}
|
|
</span>
|
|
@if(!$connectionTest['magento1'] && isset($connectionTest['magento1_error']))
|
|
<div style="color: #721c24; margin-top: 5px; font-size: 0.9em;">
|
|
{{ $connectionTest['magento1_error'] }}
|
|
</div>
|
|
@endif
|
|
</div>
|
|
<div>
|
|
<strong>Magento 2:</strong>
|
|
<span class="status-badge {{ $connectionTest['magento2'] ? 'success' : 'error' }}">
|
|
{{ $connectionTest['magento2'] ? '✓ Connected' : '✗ Failed' }}
|
|
</span>
|
|
@if(!$connectionTest['magento2'] && isset($connectionTest['magento2_error']))
|
|
<div style="color: #721c24; margin-top: 5px; font-size: 0.9em;">
|
|
{{ $connectionTest['magento2_error'] }}
|
|
</div>
|
|
@endif
|
|
</div>
|
|
</div>
|
|
<button class="btn btn-secondary" onclick="testConnections()">Test Connections</button>
|
|
</div>
|
|
|
|
<!-- Statistics -->
|
|
<div class="section">
|
|
<h2>📊 Statistics</h2>
|
|
<div class="stats">
|
|
<div class="stat-card">
|
|
<div class="number">{{ $m1Stores->count() }}</div>
|
|
<div class="label">Magento 1 Stores</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="number">{{ $m2Stores->count() }}</div>
|
|
<div class="label">Magento 2 Stores</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="number">{{ $m1CategoriesCount }}</div>
|
|
<div class="label">Magento 1 Categories</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Store Mapping -->
|
|
<div class="section">
|
|
<h2>🔄 Store Mapping</h2>
|
|
<p>Map each Magento 1 store to its corresponding Magento 2 store:</p>
|
|
|
|
<div id="store-mappings">
|
|
@foreach($m1Stores as $m1Store)
|
|
<div class="store-mapping" style="margin-top: 15px;">
|
|
<div>
|
|
<strong>M1 Store:</strong> {{ $m1Store->name }} ({{ $m1Store->code }})
|
|
</div>
|
|
<div class="arrow">→</div>
|
|
<div>
|
|
<select class="store-select" name="store_mapping[{{ $m1Store->store_id }}]" id="store_{{ $m1Store->store_id }}">
|
|
<option value="">Select Magento 2 Store</option>
|
|
@foreach($m2Stores as $m2Store)
|
|
<option value="{{ $m2Store->store_id }}">{{ $m2Store->name }} ({{ $m2Store->code }})</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
|
|
@if($m1Stores->isEmpty())
|
|
<div class="info-box">
|
|
<p>No Magento 1 stores found. Please check your database connection.</p>
|
|
</div>
|
|
@endif
|
|
</div>
|
|
|
|
<!-- Actions -->
|
|
<div class="section">
|
|
<h2>⚡ Actions</h2>
|
|
<div class="actions">
|
|
<button class="btn btn-primary" onclick="startMigration()" id="migrateBtn" {{ !$connectionTest['magento1'] || !$connectionTest['magento2'] ? 'disabled' : '' }}>
|
|
Start Migration
|
|
</button>
|
|
<button class="btn btn-secondary" onclick="previewCategories()">
|
|
Preview Categories
|
|
</button>
|
|
</div>
|
|
|
|
<div class="loading" id="loading">
|
|
<div class="spinner"></div>
|
|
<p style="margin-top: 15px;">Migration in progress...</p>
|
|
</div>
|
|
|
|
<div class="log-container" id="logContainer">
|
|
<div id="logContent"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function testConnections() {
|
|
fetch('{{ route("migration.test-connections") }}')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
alert('✓ Both database connections are working!');
|
|
location.reload();
|
|
} else {
|
|
alert('✗ Connection test failed. Check the error messages above.');
|
|
}
|
|
})
|
|
.catch(error => {
|
|
alert('Error testing connections: ' + error.message);
|
|
});
|
|
}
|
|
|
|
function previewCategories() {
|
|
fetch('{{ route("migration.magento1-categories") }}')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
let message = `Found ${data.count} categories in Magento 1.\n\nFirst 10 categories:\n\n`;
|
|
data.categories.forEach(cat => {
|
|
message += `ID: ${cat.id} - ${cat.name} (Level: ${cat.level})\n`;
|
|
});
|
|
alert(message);
|
|
} else {
|
|
alert('Failed to fetch categories');
|
|
}
|
|
})
|
|
.catch(error => {
|
|
alert('Error: ' + error.message);
|
|
});
|
|
}
|
|
|
|
function startMigration() {
|
|
const storeMapping = {};
|
|
const selects = document.querySelectorAll('select[name^="store_mapping"]');
|
|
|
|
let hasMapping = false;
|
|
selects.forEach(select => {
|
|
if (select.value) {
|
|
storeMapping[select.name.match(/\[(\d+)\]/)[1]] = select.value;
|
|
hasMapping = true;
|
|
}
|
|
});
|
|
|
|
if (!hasMapping) {
|
|
alert('Please map at least one store before starting migration.');
|
|
return;
|
|
}
|
|
|
|
if (!confirm('Are you sure you want to start the migration? This will modify your Magento 2 database.')) {
|
|
return;
|
|
}
|
|
|
|
document.getElementById('migrateBtn').disabled = true;
|
|
document.getElementById('loading').classList.add('active');
|
|
document.getElementById('logContainer').classList.add('active');
|
|
document.getElementById('logContent').innerHTML = '<div class="log-entry">Starting migration...</div>';
|
|
|
|
fetch('{{ route("migration.migrate") }}', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
|
},
|
|
body: JSON.stringify({ store_mapping: storeMapping })
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
document.getElementById('loading').classList.remove('active');
|
|
document.getElementById('migrateBtn').disabled = false;
|
|
|
|
if (data.success) {
|
|
addLogEntry(`✓ Migration completed successfully!`, 'success');
|
|
addLogEntry(`Migrated ${data.migrated_count} categories`, 'success');
|
|
|
|
if (data.log && data.log.length > 0) {
|
|
data.log.forEach(log => {
|
|
const type = log.includes('ERROR') ? 'error' : 'success';
|
|
addLogEntry(log, type);
|
|
});
|
|
}
|
|
} else {
|
|
addLogEntry(`✗ Migration failed: ${data.message}`, 'error');
|
|
if (data.log && data.log.length > 0) {
|
|
data.log.forEach(log => {
|
|
addLogEntry(log, log.includes('ERROR') ? 'error' : 'success');
|
|
});
|
|
}
|
|
}
|
|
})
|
|
.catch(error => {
|
|
document.getElementById('loading').classList.remove('active');
|
|
document.getElementById('migrateBtn').disabled = false;
|
|
addLogEntry(`✗ Error: ${error.message}`, 'error');
|
|
});
|
|
}
|
|
|
|
function addLogEntry(message, type = '') {
|
|
const logContent = document.getElementById('logContent');
|
|
const entry = document.createElement('div');
|
|
entry.className = `log-entry ${type}`;
|
|
entry.textContent = message;
|
|
logContent.appendChild(entry);
|
|
logContent.scrollTop = logContent.scrollHeight;
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|
|
|