-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathbootstrap.php
More file actions
113 lines (95 loc) · 2.74 KB
/
Copy pathbootstrap.php
File metadata and controls
113 lines (95 loc) · 2.74 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
// Uncomment to enable debugging
// ini_set('display_errors', '1');
// ini_set('error_reporting', E_ALL);
// Increase memory limit
ini_set('memory_limit', '2048M');
// Increase maximum execution time to 4 hours
//ini_set('max_execution_time', 14400);
define('MAGENTO', realpath(dirname(__FILE__)).'/..');
require_once MAGENTO . '/app/Mage.php';
// Set working directory to magento root folder
chdir(MAGENTO);
// Make files written by the profile world-writable/readable
umask(0);
echo "MEMORY USED : ".convert(memory_get_usage(true)) . "\n\n";
// Initialize the admin application
Mage::app('admin');
class Arguments
{
public static $_args;
public function __construct()
{
$this->_parseArgs();
}
/**
* Parse input arguments
*
* @return Mage_Shell_Abstract
*/
protected function _parseArgs()
{
$current = null;
foreach ($_SERVER['argv'] as $arg) {
$match = array();
if (preg_match('#^--([\w\d_-]{1,})$#', $arg, $match) || preg_match('#^-([\w\d_]{1,})$#', $arg, $match)) {
$current = $match[1];
static::$_args[$current] = true;
} else {
if ($current) {
static::$_args[$current] = $arg;
} elseif (preg_match('#^([\w\d_]{1,})$#', $arg, $match)) {
static::$_args[$match[1]] = true;
}
}
}
return $this;
}
/**
* Retrieve argument value by name or false
*
* @param string $name the argument name
* @return mixed
*/
public static function getArg($name)
{
if (isset(static::$_args[$name])) {
return static::$_args[$name];
}
return false;
}
/**
* Check if argumnets are given
*
* @return bool
*/
public static function hasArgs()
{
return count(static::$_args) !== 0;
}
}
new Arguments();
function convert($size)
{
$unit=array('b','kb','mb','gb','tb','pb');
return @round($size/pow(1024, ($i=floor(log($size, 1024)))), 2).' '.$unit[$i];
}
function writeCsv($attributesCollection, $filename = "import.csv", $delimiter = '|', $enclosure = '"')
{
$f = fopen($filename, "w") or die("Unable to open file!");
$first = true;
foreach ($attributesCollection as $line) {
if ($first) {
$titles = array();
foreach ($line as $field => $val) {
$titles[] = $field;
}
fputcsv($f, $titles, $delimiter, $enclosure);
$first = false;
}
fputcsv($f, $line, $delimiter, $enclosure);
}
fclose($f);
echo "MEMORY USED : ".convert(memory_get_usage(true)) . "\n";
echo "csv dumped to $filename \n\n";
}