1 <?php
2 3 4 5 6 7 8
9
10 class ImportCatalog1C_ProcessTask extends ScheduledTask {
11 function process() {
12 $pidFile = TEMP_FOLDER . '/import.pid';
13 if (is_file($pidFile)) {
14 $pid = (int) file_get_contents($pidFile);
15 if (posix_getsid($pid) !== false) {
16
17 return;
18 }
19 else {
20
21 unlink($pidFile);
22 }
23 }
24 file_put_contents($pidFile, getmypid());
25
26 $importerClass = ImportCatalogSiteConfig::$importer_class;
27 $importer = new $importerClass();
28 $importer::$startTime = date('Y-m-d H:i:s');
29
30
31 if ($taskQueue = DataObject::get('Import1CLog_Task', "Status = 'new'", "ID")) {
32 foreach ($taskQueue as $entry) {
33 if ($entry->Status != 'new') continue;
34
35 $filepath = Base1CExchanger::absolute_import_path($entry->Filename);
36 if (is_file($filepath)) {
37 $entry->Status = 'process';
38 $entry->write();
39
40 if ($entry->Operation == 'catalog') {
41 $importer->importCatalog($filepath, $entry->Log());
42 $entry->Status = 'finish';
43 $entry->write();
44
45 }
46
47 if ($entry->Operation == 'offers') {
48 $entry->Log()->addStage('offers');
49 if ($importer->ImportOffers($filepath, $entry->Log())) {
50 $entry->Status = 'finish';
51 $entry->write();
52
53 }
54 else {
55 $entry->Status = 'error';
56 $entry->write();
57 }
58 }
59 }
60 else {
61 $entry->Log()->addStatus('error', "File {$entry->Filename} not found");
62 break;
63 }
64 if (is_file(Base1CExchanger::absolute_import_path('stop_import'))) {
65 unlink(Base1CExchanger::absolute_import_path('stop_import'));
66 $entry->Status = 'finish';
67 $entry->write();
68
69 $entry->Log()->addStatus('ok', _t('ProductCatalogImport.ImportInterrupted', 'Импорт прерван'));
70 return;
71 }
72 }
73 }
74 unlink($pidFile);
75 }
76 }
77
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-