/
index.php
executable file
·106 lines (60 loc) · 2.53 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
ini_set('display_errors',true);
error_reporting(E_ALL);
include __DIR__.'/src/config/config.php';
require_once $config['magento_full_path'];
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\ProcessBuilder;
use Symfony\Component\Process\Process;
use Helpers\CSV\CsvHandler;
use Helpers\CSV\CsvSplitter;
use Helpers\ProcessLocker;
use Keboola\Csv\CsvFile;
use Slim\Slim;
$app = new Slim(array(
'mode'=>'development',
'templates.path' => $config['templates_path']
));
$app->get('/', function () use ($app,$config){
$app->render('page.php',array(
'csv_files_path'=> $config['csv_files_path'],
'log_files_path'=> $config['log_files_path'],
));
});
$app->get('/download_report', function () use ($app,$config){
$fileName = $app->request()->params('filename');
echo "<pre>";
echo file_get_contents($config['log_files_path'].$fileName);
});
$app->get('/process/', function () use ($app,$config){
$fileName = $app->request()->params('filename');
$locker = new ProcessLocker($config['lock_file']);
if ( ! $locker->isLocked() ) {
$splitter = new CsvSplitter(new CsvFile($fileName),$config['output_csv_path']);
$splitter->split($config['split_size']);
$command = $config['nohup_path'].' '.$config['php_path'].' '.__DIR__.'/src/shell/csv_importer.php '.$config['output_csv_path'].' > /dev/null 2>&1 &';
$process = new Process($command,$config['proc_working_path']);
$process->run();
}
$app->redirect('/csv_batch_process/index.php');
});
use Helpers\Magento\MageWrapper;
use Repositories\Magento\CatalogRepository;
use Repositories\Magento\EavCatalogProductRepository;
use Processors\Magento\ProductImporter;
$app->get('/test/', function () use ($app,$config){
ini_set('max_execution_time',-1);
Mage::app('admin', 'store', array('global_ban_use_cache'=>true))->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$mageWrapper = new MageWrapper(Mage);
$eavRepository = new EavCatalogProductRepository($mageWrapper);
$catalogRepository = new CatalogRepository($mageWrapper,$eavRepository);
$magentoProcessor = new ProductImporter($catalogRepository);
$magentoProcessor->process(new CsvFile('sample.csv'),'sample.csv');
});
$app->get('/test_splitter/', function () use ($app,$config){
$splitter = new CsvSplitter(new CsvFile('sample.csv'),$config['output_csv_path']);
$splitter->setCsvHandler(new CsvHandler);
$splitter->setFileHandler(new Filesystem);
$splitter->split(5);
});
$app->run();