1 <?php
2
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 class ImportAutoStartTask extends ScheduledTask {
22
23 static $importPath = 'images/';
24
25 static function importPath($val = false) {
26 if ($val) {
27 self::$importPath = preg_replace('!//!', '/', $val .'/');
28 }
29 return BASE_PATH . '/' . self::$importPath;
30 }
31
32 function process() {
33 if (!file_exists(self::importPath() . 'start_ok')) return;
34
35 $data = array();
36 if (file_exists(self::importPath() . 'config.xml')) {
37 $data = Convert::xml2array(file_get_contents(self::importPath() . 'config.xml'));
38 }
39
40 $data['auto'] = 1;
41 $data['importFile'] = self::importPath() . 'import.xml';
42
43 if (!file_exists($data['importFile'])) {
44 $this->sendMessage('Флаг начала импорта установлен, но не найден файл import.xml');
45 }
46 else {
47 $admin = new WebylonImportAdmin();
48 if (!$admin->startImport($data)) {
49 $config = new ImportConfig();
50 $this->sendMessage($config->getMessage());
51 }
52 }
53 unlink(self::importPath() . 'start_ok');
54 }
55
56 function sendMessage($message) {
57 $sc = SiteConfig::current_site_config();
58
59 $email = Email::getAdminEmail();
60 $mail = new Email($email, $email, 'Ошибка импорта на сайте: ' . $sc->Title, "При попытке начала автоматического импорта произошла ошибка:\n$message\n\nИмпорт не произведен.\n");
61 $mail->sendPlain();
62 }
63 }
64
65
[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.
-