AMartinez_CustomImportExport - Version 1.5.007

Version Notes

Magento 1.5 version.

Download this release

Release Info

Developer Antonio Martinez
Extension AMartinez_CustomImportExport
Version 1.5.007
Comparing to
See all releases


Code changes from version 1.5.005 to 1.5.007

app/code/community/AMartinez/CustomImportExport/Model/Backup.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * @category AMartinez
6
+ * @package AMartinez_CustomImportExport
7
+ * @author Antonio Martinez
8
+ * @copyright Copyright (c) 2011 Antonio Martínez (toniyecla@gmail.com)
9
+ * @license http://opensource.org/licenses/osl-3.0 Open Software License (OSL 3.0)
10
+ */
11
+
12
+ /**
13
+ * Backup file item model
14
+ *
15
+ * @category Mage
16
+ * @package Mage_Backup
17
+ * @author Magento Core Team <core@magentocommerce.com>
18
+ */
19
+ class AMartinez_CustomImportExport_Model_Backup extends Mage_Backup_Model_Backup
20
+ {
21
+ /**
22
+ * Backup filename
23
+ *
24
+ * @var string
25
+ */
26
+ private $_file = '';
27
+
28
+ /**
29
+ * Sets filename
30
+ *
31
+ * @param string $value
32
+ */
33
+ public function setFile($value)
34
+ {
35
+ $this->_file = $value;
36
+
37
+ return $this;
38
+ }
39
+
40
+ /**
41
+ * Return file name of backup file
42
+ *
43
+ * @return string
44
+ */
45
+ public function getFileName()
46
+ {
47
+ return $this->_file;
48
+ }
49
+ }
app/code/community/AMartinez/CustomImportExport/Model/Import.php CHANGED
@@ -26,7 +26,7 @@ class AMartinez_CustomImportExport_Model_Import extends Mage_ImportExport_Model_
26
  }
27
 
28
  /**
29
- * Validates source file and returns validation result.
30
  *
31
  * @param string $sourceFile Full path to source file
32
  * @return bool
26
  }
27
 
28
  /**
29
+ * Validates source file and returns validation result (no unlink file)
30
  *
31
  * @param string $sourceFile Full path to source file
32
  * @return bool
app/code/community/AMartinez/CustomImportExport/Model/Import/Entity/Customer.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * @category AMartinez
6
+ * @package AMartinez_CustomImportExport
7
+ * @author Antonio Martinez
8
+ * @copyright Copyright (c) 2011 Antonio Martínez (toniyecla@gmail.com)
9
+ * @license http://opensource.org/licenses/osl-3.0 Open Software License (OSL 3.0)
10
+ */
11
+
12
+ /**
13
+ * Import entity customer model
14
+ *
15
+ */
16
+ class AMartinez_CustomImportExport_Model_Import_Entity_Customer extends Mage_ImportExport_Model_Import_Entity_Customer
17
+ {
18
+
19
+ }
app/code/community/AMartinez/CustomImportExport/Model/Import/Entity/Customer/Address.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * @category AMartinez
6
+ * @package AMartinez_CustomImportExport
7
+ * @author Antonio Martinez
8
+ * @copyright Copyright (c) 2011 Antonio Martínez (toniyecla@gmail.com)
9
+ * @license http://opensource.org/licenses/osl-3.0 Open Software License (OSL 3.0)
10
+ */
11
+
12
+ /**
13
+ * Import entity customer address
14
+ *
15
+ */
16
+ class AMartinez_CustomImportExport_Model_Import_Entity_Customer_Address extends Mage_ImportExport_Model_Import_Entity_Customer_Address
17
+ {
18
+
19
+ }
app/code/community/AMartinez/CustomImportExport/etc/config.xml CHANGED
@@ -14,7 +14,7 @@
14
 
15
  <modules>
16
  <AMartinez_CustomImportExport>
17
- <version>1.5.005</version>
18
  <depends>
19
  <!-- no dependencies -->
20
  </depends>
@@ -42,7 +42,7 @@
42
  <label>Products</label>
43
  </catalog_product>
44
  <customer translate="label">
45
- <model_token>importexport/import_entity_customer</model_token>
46
  <label>Customers</label>
47
  </customer>
48
  </import_entities>
@@ -61,6 +61,10 @@
61
  <sourcefile>var/customimportexport/productsimport.csv</sourcefile>
62
  <outputfile>var/customimportexport/productsexport.csv</outputfile>
63
  </products>
 
 
 
 
64
  </customimportexport>
65
  </default>
66
 
14
 
15
  <modules>
16
  <AMartinez_CustomImportExport>
17
+ <version>1.5.007</version>
18
  <depends>
19
  <!-- no dependencies -->
20
  </depends>
42
  <label>Products</label>
43
  </catalog_product>
44
  <customer translate="label">
45
+ <model_token>customimportexport/import_entity_customer</model_token>
46
  <label>Customers</label>
47
  </customer>
48
  </import_entities>
61
  <sourcefile>var/customimportexport/productsimport.csv</sourcefile>
62
  <outputfile>var/customimportexport/productsexport.csv</outputfile>
63
  </products>
64
+ <customers>
65
+ <sourcefile>var/customimportexport/customersimport.csv</sourcefile>
66
+ <outputfile>var/customimportexport/customersexport.csv</outputfile>
67
+ </customers>
68
  </customimportexport>
69
  </default>
70
 
app/code/community/AMartinez/CustomImportExport/shell/run.php CHANGED
@@ -25,19 +25,45 @@ class AMartinez_CustomImportExport extends Mage_Shell_Abstract
25
  Mage::setIsDeveloperMode(true);
26
  ini_set('display_errors', 1);
27
  // ini_set("memory_limit","2048M");
28
-
29
- $import = $this->initImportModel();
30
-
31
  // help
32
  if ($this->getArg('h') || $this->getArg('help') || count($this->_args) == 0)
33
  {
34
  die($this->usageHelp());
35
  }
36
-
37
- // import
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  if ($file = $this->getSourceFile()) {
39
- echo "Start import from source file $file\n";
40
- Mage::log("Start import from source file $file", Zend_Log::DEBUG);
41
 
42
  $validationResult = $import->validateSource($file);
43
  $processedRowsCount = $import->getProcessedRowsCount();
@@ -73,10 +99,10 @@ class AMartinez_CustomImportExport extends Mage_Shell_Abstract
73
  echo "Done (processed rows count: " . $processedRowsCount . ")\n";
74
  }
75
 
76
- // export
77
  if ($file = $this->getOutputFile()) {
78
- echo "Start output to file $file\n";
79
- Mage::log("Start output to file $file", Zend_Log::DEBUG);
80
 
81
  $export = $this->initExportModel();
82
  if ($f = fopen($file, 'w'))
@@ -84,16 +110,63 @@ class AMartinez_CustomImportExport extends Mage_Shell_Abstract
84
  $result = $export->export();
85
  fwrite($f, $result);
86
  fclose($f);
87
- echo "Done (processed rows count: " . substr_count($result, "\n") . ")\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  }
89
  else
90
  {
91
- echo "Cannot output to file $file\n";
92
  };
93
  }
94
 
95
  // index
96
- if ($this->getArg('r') || $this->getArg('reindex'))
97
  {
98
  echo "Reindexing data...\n";
99
  try
@@ -104,7 +177,7 @@ class AMartinez_CustomImportExport extends Mage_Shell_Abstract
104
  }
105
 
106
  // cache
107
- if ($this->getArg('c') || $this->getArg('cleancache'))
108
  {
109
  echo "Cleaning cache...\n";
110
  try
@@ -115,7 +188,7 @@ class AMartinez_CustomImportExport extends Mage_Shell_Abstract
115
  }
116
 
117
  // image files
118
- if ($this->getArg('f') || $this->getArg('flushimages'))
119
  {
120
  echo "Erasing catalog images cache...\n";
121
  try
@@ -126,7 +199,7 @@ class AMartinez_CustomImportExport extends Mage_Shell_Abstract
126
  }
127
 
128
  // price rules
129
- if ($this->getArg('p') || $this->getArg('applyrules'))
130
  {
131
  echo "Recalculating catalog price rules...\n";
132
  try
@@ -138,7 +211,7 @@ class AMartinez_CustomImportExport extends Mage_Shell_Abstract
138
  }
139
 
140
  /**
141
- * Initialize import model
142
  *
143
  * @return AMartinez_CustomImportExport_Model_Import
144
  */
@@ -146,13 +219,13 @@ class AMartinez_CustomImportExport extends Mage_Shell_Abstract
146
  {
147
  $import = Mage::getModel('customimportexport/import');
148
  $import->setEntity('catalog_product');
149
- $import->setBehavior('replace');
150
 
151
  return $import;
152
  }
153
 
154
  /**
155
- * Return the specified source file
156
  *
157
  * @return string
158
  */
@@ -170,7 +243,7 @@ class AMartinez_CustomImportExport extends Mage_Shell_Abstract
170
  }
171
  else
172
  {
173
- echo "Skipping source file $option1\n";
174
  }
175
  }
176
  if ($option2 && $option2 != 1)
@@ -181,7 +254,7 @@ class AMartinez_CustomImportExport extends Mage_Shell_Abstract
181
  }
182
  else
183
  {
184
- echo "Skipping source file $option2\n";
185
  }
186
  }
187
  if ($default = Mage::getStoreConfig('customimportexport/products/sourcefile'))
@@ -192,18 +265,18 @@ class AMartinez_CustomImportExport extends Mage_Shell_Abstract
192
  }
193
  else
194
  {
195
- echo "Skipping default source file $default\n";
196
  }
197
  }
198
  else
199
  {
200
- echo "No default source file found in config.xml\n";
201
  }
202
  }
203
  }
204
 
205
  /**
206
- * Initialize export model
207
  *
208
  * @return AMartinez_CustomImportExport_Model_Export
209
  */
@@ -217,7 +290,7 @@ class AMartinez_CustomImportExport extends Mage_Shell_Abstract
217
  }
218
 
219
  /**
220
- * Return the specified output file
221
  *
222
  * @return string
223
  */
@@ -241,10 +314,162 @@ class AMartinez_CustomImportExport extends Mage_Shell_Abstract
241
  }
242
  else
243
  {
244
- echo "No default output file found in config.xml\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  }
246
  }
247
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
 
249
  /**
250
  * Retrieve usage help message
@@ -252,7 +477,7 @@ class AMartinez_CustomImportExport extends Mage_Shell_Abstract
252
  public function usageHelp()
253
  {
254
  return <<<HELP
255
- AMartinez_CustomImportExport script (v. 1.5.005)
256
 
257
  NAME
258
  run.php
@@ -262,44 +487,64 @@ SYNOPSIS
262
  php -f app/code/community/AMartinez/CustomImportExport/shell/run.php [-- [OPTIONS...]]
263
 
264
  DESCRIPTION
265
- Import/Export products from/to CSV file. Create categories, add attribute options, reindex, refresh cache, images and price rules automatically.
266
 
267
  OPTIONS
268
  -h
269
  -help
270
- print this usage and exit
 
 
 
 
 
 
 
 
271
 
272
  -c
273
  -cleancache
274
- clean cache storage (html output, etc)
 
 
 
 
275
 
276
- -e <file>
277
- -export <file>
278
- output products to csv file, if output file not specified uses defined in config.xml
279
 
280
- -i <file>
281
- -import <file>
282
- import products from csv file, if source file not specified or not found uses defined in config.xml
 
 
 
 
 
 
 
 
283
 
284
  -f
285
  -flushimages
286
- flush catalog images cache
287
 
288
  -p
289
  -applyrules
290
- recalculate catalog price rules
291
 
292
  -r
293
  -reindex
294
- reindex data by all indexers (attributes, prices, etc)
295
 
296
  EXAMPLES
297
- php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -source var/importexport/products.csv
298
- php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -reindex
299
- php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -c -f -p -r -i var/importexport/products.csv
300
- php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -export
301
  php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -e var/importexport/products.csv
302
-
 
303
 
304
  HELP;
305
  }
25
  Mage::setIsDeveloperMode(true);
26
  ini_set('display_errors', 1);
27
  // ini_set("memory_limit","2048M");
28
+
 
 
29
  // help
30
  if ($this->getArg('h') || $this->getArg('help') || count($this->_args) == 0)
31
  {
32
  die($this->usageHelp());
33
  }
34
+
35
+ // database export
36
+ if ($backup = $this->initDatabaseBackupModel()) {
37
+ echo "Start database output to file " . $backup->getPath() . DS . $backup->getFilename() . "\n";
38
+ Mage::log("Start database output to file " . $backup->getPath() . DS . $backup->getFilename(), Zend_Log::DEBUG);
39
+
40
+ $backupDb = Mage::getModel('backup/db');
41
+ Mage::register('backup_model', $backup);
42
+ if ($backupDb->createBackup($backup)) {
43
+ echo "Done.\n";
44
+ }
45
+ }
46
+
47
+ // behavior
48
+ if ($this->getArg('b'))
49
+ {
50
+ $this->behavior = $this->getArg('b');
51
+ }
52
+ elseif ($this->getArg('behavior'))
53
+ {
54
+ $this->behavior = $this->getArg('behavior');
55
+ }
56
+ else
57
+ {
58
+ $this->behavior = 'replace';
59
+ }
60
+
61
+ $import = $this->initImportModel();
62
+
63
+ // products import
64
  if ($file = $this->getSourceFile()) {
65
+ echo "Start '$this->behavior' action. Products source file $file\n";
66
+ Mage::log("Start '$this->behavior' action. Products source file $file", Zend_Log::DEBUG);
67
 
68
  $validationResult = $import->validateSource($file);
69
  $processedRowsCount = $import->getProcessedRowsCount();
99
  echo "Done (processed rows count: " . $processedRowsCount . ")\n";
100
  }
101
 
102
+ // products export
103
  if ($file = $this->getOutputFile()) {
104
+ echo "Start products output to file $file\n";
105
+ Mage::log("Start products output to file $file", Zend_Log::DEBUG);
106
 
107
  $export = $this->initExportModel();
108
  if ($f = fopen($file, 'w'))
110
  $result = $export->export();
111
  fwrite($f, $result);
112
  fclose($f);
113
+ echo "Done (processed rows count: " . (substr_count($result, "\n") - 1). ")\n";
114
+ }
115
+ else
116
+ {
117
+ echo "Cannot output products to file $file\n";
118
+ };
119
+ }
120
+
121
+ // customers import
122
+ if ($file = $this->getCustomersSourceFile()) {
123
+ echo "Start '$this->behavior' action. Customers source file $file\n";
124
+ Mage::log("Start '$this->behavior' action. Customers source file $file", Zend_Log::DEBUG);
125
+
126
+ $customersimport = $this->initCustomersImportModel();
127
+ $validationResult = $customersimport->validateSource($file);
128
+ $processedRowsCount = $customersimport->getProcessedRowsCount();
129
+
130
+ if ($processedRowsCount > 0)
131
+ {
132
+ if (!$validationResult)
133
+ {
134
+ $message = sprintf("File %s contains %s corrupt records (from a total of %s)",
135
+ $file, $customersimport->getInvalidRowsCount(), $processedRowsCount
136
+ );
137
+ foreach ($customersimport->getErrors() as $type => $lines)
138
+ {
139
+ $message .= "\n:::: " . $type . " ::::\nIn Line(s) " . implode(", ", $lines) . "\n";
140
+ }
141
+ Mage::throwException($message);
142
+ }
143
+
144
+ $customersimport->importSource();
145
+ }
146
+ echo "Done (processed rows count: " . $processedRowsCount . ")\n";
147
+ }
148
+
149
+ // customers export
150
+ if ($file = $this->getCustomersOutputFile()) {
151
+ echo "Start customers output to file $file\n";
152
+ Mage::log("Start customers output to file $file", Zend_Log::DEBUG);
153
+
154
+ $customersexport = $this->initCustomersExportModel();
155
+ if ($f = fopen($file, 'w'))
156
+ {
157
+ $result = $customersexport->export();
158
+ fwrite($f, $result);
159
+ fclose($f);
160
+ echo "Done (processed rows count: " . (substr_count($result, "\n") - 1) . ")\n";
161
  }
162
  else
163
  {
164
+ echo "Cannot output customers to file $file\n";
165
  };
166
  }
167
 
168
  // index
169
+ if ($this->getArg('r') || $this->getArg('reindex') || $this->getArg('a') || $this->getArg('all'))
170
  {
171
  echo "Reindexing data...\n";
172
  try
177
  }
178
 
179
  // cache
180
+ if ($this->getArg('c') || $this->getArg('cleancache') || $this->getArg('a') || $this->getArg('all'))
181
  {
182
  echo "Cleaning cache...\n";
183
  try
188
  }
189
 
190
  // image files
191
+ if ($this->getArg('f') || $this->getArg('flushimages') || $this->getArg('a') || $this->getArg('all'))
192
  {
193
  echo "Erasing catalog images cache...\n";
194
  try
199
  }
200
 
201
  // price rules
202
+ if ($this->getArg('p') || $this->getArg('applyrules') || $this->getArg('a') || $this->getArg('all'))
203
  {
204
  echo "Recalculating catalog price rules...\n";
205
  try
211
  }
212
 
213
  /**
214
+ * Initialize products import model
215
  *
216
  * @return AMartinez_CustomImportExport_Model_Import
217
  */
219
  {
220
  $import = Mage::getModel('customimportexport/import');
221
  $import->setEntity('catalog_product');
222
+ $import->setBehavior($this->behavior);
223
 
224
  return $import;
225
  }
226
 
227
  /**
228
+ * Return the specified products source file
229
  *
230
  * @return string
231
  */
243
  }
244
  else
245
  {
246
+ echo "Skipping products source file $option1\n";
247
  }
248
  }
249
  if ($option2 && $option2 != 1)
254
  }
255
  else
256
  {
257
+ echo "Skipping products source file $option2\n";
258
  }
259
  }
260
  if ($default = Mage::getStoreConfig('customimportexport/products/sourcefile'))
265
  }
266
  else
267
  {
268
+ echo "Skipping default products source file $default\n";
269
  }
270
  }
271
  else
272
  {
273
+ echo "No default products source file found in config.xml\n";
274
  }
275
  }
276
  }
277
 
278
  /**
279
+ * Initialize products export model
280
  *
281
  * @return AMartinez_CustomImportExport_Model_Export
282
  */
290
  }
291
 
292
  /**
293
+ * Return the specified products output file
294
  *
295
  * @return string
296
  */
314
  }
315
  else
316
  {
317
+ echo "No default products output file found in config.xml\n";
318
+ }
319
+ }
320
+ }
321
+
322
+ /**
323
+ * Initialize customers import model
324
+ *
325
+ * @return AMartinez_CustomImportExport_Model_Import
326
+ */
327
+ public function initCustomersImportModel()
328
+ {
329
+ $customersimport = Mage::getModel('customimportexport/import');
330
+ $customersimport->setEntity('customer');
331
+ $customersimport->setBehavior($this->behavior);
332
+
333
+ return $customersimport;
334
+ }
335
+
336
+ /**
337
+ * Return the specified customers source file
338
+ *
339
+ * @return string
340
+ */
341
+ public function getCustomersSourceFile()
342
+ {
343
+ $option1 = $this->getArg('ci');
344
+ $option2 = $this->getArg('customersimport');
345
+ if ($option1 || $option2)
346
+ {
347
+ if ($option1 && $option1 != 1)
348
+ {
349
+ if (file_exists($option1))
350
+ {
351
+ return $option1;
352
+ }
353
+ else
354
+ {
355
+ echo "Skipping customers source file $option1\n";
356
+ }
357
+ }
358
+ if ($option2 && $option2 != 1)
359
+ {
360
+ if (file_exists($option2))
361
+ {
362
+ return $option2;
363
+ }
364
+ else
365
+ {
366
+ echo "Skipping customers source file $option2\n";
367
+ }
368
+ }
369
+ if ($default = Mage::getStoreConfig('customimportexport/customers/sourcefile'))
370
+ {
371
+ if(file_exists($default))
372
+ {
373
+ return $default;
374
+ }
375
+ else
376
+ {
377
+ echo "Skipping default customers source file $default\n";
378
+ }
379
+ }
380
+ else
381
+ {
382
+ echo "No default customers source file found in config.xml\n";
383
+ }
384
+ }
385
+ }
386
+
387
+ /**
388
+ * Initialize customers export model
389
+ *
390
+ * @return AMartinez_CustomImportExport_Model_Export
391
+ */
392
+ public function initCustomersExportModel()
393
+ {
394
+ $customersexport = Mage::getModel('customimportexport/export');
395
+ $customersexport->setEntity('customer');
396
+ $customersexport->setData('file_format', 'csv');
397
+
398
+ return $customersexport;
399
+ }
400
+
401
+ /**
402
+ * Return the specified customers output file
403
+ *
404
+ * @return string
405
+ */
406
+ public function getCustomersOutputFile()
407
+ {
408
+ $option1 = $this->getArg('ce');
409
+ $option2 = $this->getArg('customersexport');
410
+ if ($option1 || $option2)
411
+ {
412
+ if ($option1 && $option1 != 1)
413
+ {
414
+ return $option1;
415
+ }
416
+ if ($option2 && $option2 != 1)
417
+ {
418
+ return $option2;
419
+ }
420
+ if ($default = Mage::getStoreConfig('customimportexport/customers/outputfile'))
421
+ {
422
+ return $default;
423
+ }
424
+ else
425
+ {
426
+ echo "No default customers output file found in config.xml\n";
427
  }
428
  }
429
  }
430
+
431
+ /**
432
+ * Initialize database export model
433
+ *
434
+ * @return AMartinez_CustomImportExport_Model_Backup
435
+ */
436
+ public function initDatabaseBackupModel()
437
+ {
438
+ $option1 = $this->getArg('db');
439
+ $option2 = $this->getArg('databasebackup');
440
+ if ($option1 || $option2)
441
+ {
442
+ $backup = Mage::getModel('customimportexport/backup')
443
+ ->setType('db');
444
+ if ($option1 && $option1 != 1)
445
+ {
446
+ $fileinfo = pathinfo($option1);
447
+ if (substr($fileinfo['dirname'], 0) != DS) {
448
+ $fileinfo['dirname'] = Mage::getBaseDir() . DS . $fileinfo['dirname'];
449
+ }
450
+ $backup->setPath($fileinfo['dirname'])
451
+ ->setFile($fileinfo['basename']);
452
+ return $backup;
453
+ }
454
+ if ($option2 && $option2 != 1)
455
+ {
456
+ $fileinfo = pathinfo($option2);
457
+ if (substr($fileinfo['dirname'], 0) != DS) {
458
+ $fileinfo['dirname'] = Mage::getBaseDir() . DS . $fileinfo['dirname'];
459
+ }
460
+ $backup->setPath($fileinfo['dirname'])
461
+ ->setFile($fileinfo['basename']);
462
+ return $backup;
463
+ }
464
+ $backup->setPath(Mage::getBaseDir("var") . DS . "backups")
465
+ ->setFile(time() . "_" . $backup->getType() . ".gz");
466
+ return $backup;
467
+ }
468
+ else
469
+ {
470
+ return false;
471
+ }
472
+ }
473
 
474
  /**
475
  * Retrieve usage help message
477
  public function usageHelp()
478
  {
479
  return <<<HELP
480
+ AMartinez_CustomImportExport script (v. 1.5.006)
481
 
482
  NAME
483
  run.php
487
  php -f app/code/community/AMartinez/CustomImportExport/shell/run.php [-- [OPTIONS...]]
488
 
489
  DESCRIPTION
490
+ Import/Export products and customeres from/to CSV file. Create categories, add attribute options, reindex, refresh cache, images and price rules automatically. In addition you can backup the entire database in SQL format.
491
 
492
  OPTIONS
493
  -h
494
  -help
495
+ print this usage and exit
496
+
497
+ -a
498
+ -all
499
+ same as -c -f -p -r
500
+
501
+ -b
502
+ -behavior
503
+ set import behavior: append|delete|replace (default)
504
 
505
  -c
506
  -cleancache
507
+ clean cache storage (html output, etc)
508
+
509
+ -ce [file]
510
+ -customersexport [file]
511
+ output customers to csv file, if output file not specified uses defined in config.xml
512
 
513
+ -ci [file]
514
+ -customersimport [file]
515
+ import customers from csv file, if source file not specified or not found uses defined in config.xml
516
 
517
+ -db [file]
518
+ -databasebackup [file]
519
+ output whole magento database to sql file and try to gzcompress it, if output file not specified uses time generated name.
520
+
521
+ -e [file]
522
+ -export [file]
523
+ output products to csv file, if output file not specified uses defined in config.xml
524
+
525
+ -i [file]
526
+ -import [file]
527
+ import products from csv file, if source file not specified or not found uses defined in config.xml
528
 
529
  -f
530
  -flushimages
531
+ flush catalog images cache
532
 
533
  -p
534
  -applyrules
535
+ recalculate catalog price rules
536
 
537
  -r
538
  -reindex
539
+ reindex data by all indexers (attributes, prices, etc)
540
 
541
  EXAMPLES
542
+ php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -import var/importexport/products.csv
543
+ php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -all
544
+ php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -a -i var/importexport/products.csv
 
545
  php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -e var/importexport/products.csv
546
+ php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -databasebackup -import -all
547
+
548
 
549
  HELP;
550
  }
package.xml CHANGED
@@ -1,22 +1,27 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>AMartinez_CustomImportExport</name>
4
- <version>1.5.005</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>Import products to Magento database from CSV file, creating categories and attribute options automatically.</summary>
10
- <description>This extension can Import/Export products from/to CSV file. Create categories, add attribute options, reindex, refresh cache, images and price rules automatically.&#xD;
11
  &#xD;
12
  It extends Mage_ImportExport class, so it is the most SCALABLE, SAFER and FASTER method exists.&#xD;
13
  &#xD;
14
  Imports:&#xD;
15
- with extension .csv: multiple-row new csv files&#xD;
16
- with extension .csv1: previous single-row with multiple values csv files ..."CAT1,CAT2,CAT3","ASSOCIATED1,ASSOCIATED2"...&#xD;
 
 
17
  &#xD;
18
- Exports: &#xD;
19
- with extension .csv: multiple-row new csv files&#xD;
 
 
 
20
  &#xD;
21
  To daily automatize imports, you must call "run.php" via crontab or similar.&#xD;
22
  &#xD;
@@ -28,46 +33,63 @@ USE:&#xD;
28
  OPTIONS&#xD;
29
  -h&#xD;
30
  -help&#xD;
31
- print this usage and exit&#xD;
 
 
 
 
 
 
 
 
32
  &#xD;
33
  -c&#xD;
34
  -cleancache&#xD;
35
- clean cache storage (html output, etc)&#xD;
 
 
 
 
 
 
 
 
36
  &#xD;
37
- -e &lt;file&gt;&#xD;
38
- -export &lt;file&gt;&#xD;
39
- output products to csv file, if output file not specified uses defined in config.xml&#xD;
 
 
 
 
40
  &#xD;
41
- -i &lt;file&gt;&#xD;
42
- -import &lt;file&gt;&#xD;
43
- import products from csv file, if source file not specified or not found uses defined in config.xml&#xD;
44
  &#xD;
45
  -f&#xD;
46
  -flushimages&#xD;
47
- flush catalog images cache&#xD;
48
  &#xD;
49
  -p&#xD;
50
  -applyrules&#xD;
51
- recalculate catalog price rules&#xD;
52
  &#xD;
53
  -r&#xD;
54
  -reindex&#xD;
55
- reindex data by all indexers (attributes, prices, etc)&#xD;
56
  &#xD;
57
  EXAMPLES&#xD;
58
- php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -source var/importexport/products.csv&#xD;
59
- php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -reindex&#xD;
60
- php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -c -f -p -r -i var/importexport/products.csv&#xD;
61
- php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -export&#xD;
62
  php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -e var/importexport/products.csv&#xD;
63
- &#xD;
64
- &#xD;
65
- More options is coming soon!</description>
66
  <notes>Magento 1.5 version.</notes>
67
  <authors><author><name>Antonio Martinez</name><user>amartinez</user><email>toniyecla@gmail.com</email></author></authors>
68
- <date>2011-05-05</date>
69
- <time>11:35:43</time>
70
- <contents><target name="magecommunity"><dir name="AMartinez"><dir name="CustomImportExport"><dir name="Helper"><file name="Data.php" hash="0c8b64920ba9cf893513573bbbb55549"/></dir><dir name="Model"><file name="Export.php" hash="010ef7eb6564b48a721dd32b0ee4c3e8"/><dir name="Import"><dir name="Adapter"><file name="Csv1.php" hash="fa713ee0bc9034befd91eee758fc2d0a"/></dir><file name="Adapter.php" hash="6d7d568cc3dfe002763638513bc04b7f"/><dir name="Entity"><dir name="Product"><dir name="Type"><file name="Configurable.php" hash="3614bf1abe10bb500219c787c2a6ebcc"/><file name="Grouped.php" hash="b7c054303353d88e5d0c9fd303670ef5"/><file name="Simple.php" hash="48cdfdfc5c2e42b011e83483f50690c4"/></dir></dir><file name="Product.php" hash="1a4bd575430a4e10af00045dc5c84fa9"/></dir></dir><file name="Import.php" hash="ac94315dc71c43dcbbd49146e4714723"/></dir><dir name="etc"><file name="config.xml" hash="4d6bd194380dbc4a5eb14c67c2ae1c56"/></dir><dir name="shell"><file name="run.php" hash="c90eb33d5a7bdc88184ef57967299d7b"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="AMartinez_CustomImportExport.xml" hash="75ba4fbc265d1cf2b6ab61b8f3a3b95e"/></dir></target><target name="mage"><dir name="var"><dir name="customimportexport"><file name="productsexport.csv" hash="be786ce510a058241f16c17353efba47"/><file name="test_configurable.csv" hash="da1cb8fea77cc7ee591e3488d12ca6d8"/><file name="test_grouped.csv" hash="1281612b7e89e4681367e654631b2521"/><file name="test_single_row_style.csv1" hash="dfcd266cb65ab97e93f9402e4f32bffb"/></dir></dir></target></contents>
71
  <compatible/>
72
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
73
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>AMartinez_CustomImportExport</name>
4
+ <version>1.5.007</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>This extension can Import/Export products and customers from/to CSV file. Create categories, add attribute options, reindex, refresh cache, images and price rules automatically. In addition you can backup the entire database in SQL format.</summary>
10
+ <description>This extension can Import/Export products and customers from/to CSV file. Create categories, add attribute options, reindex, refresh cache, images and price rules automatically. In addition you can backup the entire database in SQL format.&#xD;
11
  &#xD;
12
  It extends Mage_ImportExport class, so it is the most SCALABLE, SAFER and FASTER method exists.&#xD;
13
  &#xD;
14
  Imports:&#xD;
15
+ (products, customers)&#xD;
16
+ file.csv: multiple-row new csv files&#xD;
17
+ (products)&#xD;
18
+ file.csv1: previous single-row with multiple values csv files ..."CAT1,CAT2,CAT3","ASSOCIATED1,ASSOCIATED2"...&#xD;
19
  &#xD;
20
+ Exports:&#xD;
21
+ (products, customers)&#xD;
22
+ file.csv: multiple-row new csv files&#xD;
23
+ (database)&#xD;
24
+ backup all tables to SQL gz-compressed file&#xD;
25
  &#xD;
26
  To daily automatize imports, you must call "run.php" via crontab or similar.&#xD;
27
  &#xD;
33
  OPTIONS&#xD;
34
  -h&#xD;
35
  -help&#xD;
36
+ print this usage and exit&#xD;
37
+ &#xD;
38
+ -a&#xD;
39
+ -all&#xD;
40
+ same as -c -f -p -r&#xD;
41
+ &#xD;
42
+ -b&#xD;
43
+ -behavior&#xD;
44
+ set import behavior: append|delete|replace (default)&#xD;
45
  &#xD;
46
  -c&#xD;
47
  -cleancache&#xD;
48
+ clean cache storage (html output, etc)&#xD;
49
+ &#xD;
50
+ -ce [file]&#xD;
51
+ -customersexport [file]&#xD;
52
+ output customers to csv file, if output file not specified uses defined in config.xml&#xD;
53
+ &#xD;
54
+ -ci [file]&#xD;
55
+ -customersimport [file]&#xD;
56
+ import customers from csv file, if source file not specified or not found uses defined in config.xml&#xD;
57
  &#xD;
58
+ -db [file]&#xD;
59
+ -databasebackup [file]&#xD;
60
+ output whole magento database to sql file and try to gzcompress it, if output file not specified uses time generated name.&#xD;
61
+ &#xD;
62
+ -e [file]&#xD;
63
+ -export [file]&#xD;
64
+ output products to csv file, if output file not specified uses defined in config.xml&#xD;
65
  &#xD;
66
+ -i [file]&#xD;
67
+ -import [file]&#xD;
68
+ import products from csv file, if source file not specified or not found uses defined in config.xml&#xD;
69
  &#xD;
70
  -f&#xD;
71
  -flushimages&#xD;
72
+ flush catalog images cache&#xD;
73
  &#xD;
74
  -p&#xD;
75
  -applyrules&#xD;
76
+ recalculate catalog price rules&#xD;
77
  &#xD;
78
  -r&#xD;
79
  -reindex&#xD;
80
+ reindex data by all indexers (attributes, prices, etc)&#xD;
81
  &#xD;
82
  EXAMPLES&#xD;
83
+ php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -import var/importexport/products.csv&#xD;
84
+ php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -all&#xD;
85
+ php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -a -i var/importexport/products.csv&#xD;
 
86
  php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -e var/importexport/products.csv&#xD;
87
+ php -f app/code/community/AMartinez/CustomImportExport/shell/run.php -- -databasebackup -import -all</description>
 
 
88
  <notes>Magento 1.5 version.</notes>
89
  <authors><author><name>Antonio Martinez</name><user>amartinez</user><email>toniyecla@gmail.com</email></author></authors>
90
+ <date>2011-05-08</date>
91
+ <time>21:37:50</time>
92
+ <contents><target name="magecommunity"><dir name="AMartinez"><dir name="CustomImportExport"><dir name="Helper"><file name="Data.php" hash="0c8b64920ba9cf893513573bbbb55549"/></dir><dir name="Model"><file name="Backup.php" hash="fcdfe4eaa58adcacb0ae46c74d8698bd"/><file name="Export.php" hash="010ef7eb6564b48a721dd32b0ee4c3e8"/><dir name="Import"><dir name="Adapter"><file name="Csv1.php" hash="fa713ee0bc9034befd91eee758fc2d0a"/></dir><file name="Adapter.php" hash="6d7d568cc3dfe002763638513bc04b7f"/><dir name="Entity"><dir name="Customer"><file name="Address.php" hash="d8bead4d90523f54a451b0fc55ff1462"/></dir><file name="Customer.php" hash="d1af4445b6a38f77feaf843623658955"/><dir name="Product"><dir name="Type"><file name="Configurable.php" hash="3614bf1abe10bb500219c787c2a6ebcc"/><file name="Grouped.php" hash="b7c054303353d88e5d0c9fd303670ef5"/><file name="Simple.php" hash="48cdfdfc5c2e42b011e83483f50690c4"/></dir></dir><file name="Product.php" hash="1a4bd575430a4e10af00045dc5c84fa9"/></dir></dir><file name="Import.php" hash="df2c81435b1ceb01170abc64daf7d3a4"/></dir><dir name="etc"><file name="config.xml" hash="779fb99681ad86ca9df08aa3b30fe4ec"/></dir><dir name="shell"><file name="run.php" hash="542b56ae6dbc095173cfe426af993da9"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="AMartinez_CustomImportExport.xml" hash="75ba4fbc265d1cf2b6ab61b8f3a3b95e"/></dir></target><target name="mage"><dir name="var"><dir name="customimportexport"><file name="customersexport.csv" hash="39e55a50b73e0aadab7f7c1ea4a93f1d"/><file name="productsexport.csv" hash="be786ce510a058241f16c17353efba47"/><file name="test_configurable.csv" hash="da1cb8fea77cc7ee591e3488d12ca6d8"/><file name="test_grouped.csv" hash="1281612b7e89e4681367e654631b2521"/><file name="test_single_row_style.csv1" hash="dfcd266cb65ab97e93f9402e4f32bffb"/></dir></dir></target></contents>
93
  <compatible/>
94
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
95
  </package>
var/customimportexport/customersexport.csv ADDED
@@ -0,0 +1,2 @@
 
 
1
+ email,_website,_store,website_id,store_id,created_in,prefix,firstname,middlename,lastname,suffix,group_id,dob,password_hash,taxvat,confirmation,created_at,gender,password,_address_city,_address_company,_address_country_id,_address_fax,_address_firstname,_address_lastname,_address_middlename,_address_postcode,_address_prefix,_address_region,_address_street,_address_suffix,_address_telephone,_address_default_billing_,_address_default_shipping_
2
+ prueba@prueba.com,admin,admin,0,0,Admin,,prueba,,prueba,,1,,5640602a3fe01e40b880778c4351bbb3:5c,,,"2011-05-05 21:43:03",Male,,yecla,,ES,,prueba,prueba,,30510,,Murcia,prueba,,999999999,1,1