1 <?php
2
3 4 5 6 7
8 class ImportConfig extends Object {
9
10 public $clearDatabaseProducts = false;
11 public $clearDatabaseCatalog = false;
12 public $onlyOffers = false;
13 private $status = 'start';
14 private $cursorValue = null;
15 public $allOffers = 0;
16 public $startTime = null;
17 public $endTime = null;
18 private $message = '';
19
20 21 22 23
24 public function getStatus() {
25 return $this->status;
26 }
27
28 public function setStatus($value) {
29 $this->status = $value;
30 }
31
32 public function getMessage() {
33 return $this->message;
34 }
35
36 public function setMessage($value) {
37 $this->message = $value;
38 }
39
40 static private function file() {
41 return ASSETS_PATH . '/_import/config';
42 }
43
44 static private function cursor() {
45 return ASSETS_PATH . '/_import/cursor';
46 }
47
48 public function __construct() {
49 $file = ImportConfig::file();
50
51 if (file_exists($file)) {
52 $data = file_get_contents($file);
53 $config = unserialize($data);
54
55 $this->clearDatabaseCatalog = $config['clearCatalog'];
56 $this->clearDatabaseProducts = $config['clearProduct'];
57 $this->onlyOffers = $config['onlyOffers'];
58 $this->allOffers = $config['allOffers'];
59 $this->setStatus($config['status']);
60 $this->startTime = $config['startTime'];
61 $this->endTime = $config['endTime'];
62 $this->message = $config['message'];
63 };
64 }
65
66 public function write() {
67 $config = array(
68 'clearCatalog' => $this->clearDatabaseCatalog,
69 'clearProduct' => $this->clearDatabaseProducts,
70 'onlyOffers' => $this->onlyOffers,
71 'allOffers' => $this->allOffers,
72 'status' => $this->getStatus(),
73 'startTime' => $this->startTime,
74 'endTime' => $this->endTime,
75 'message' => $this->message
76 );
77
78 $folderPath = dirname(ImportConfig::file());
79 if (!file_exists($folderPath)) {
80 mkdir($folderPath, Filesystem::$folder_create_mask);
81 }
82
83 $f = fopen(ImportConfig::file(), 'w+');
84 fwrite($f, serialize($config));
85 fclose($f);
86 @chmod(ImportConfig::file(), 0666);
87 }
88
89 static function delete() {
90 if(file_exists(ImportConfig::file())) unlink(ImportConfig::file());
91 if(file_exists(ImportConfig::cursor())) unlink(ImportConfig::cursor());
92 }
93
94 public function getCursor() {
95 if ($this->cursorValue == null) {
96 if (file_exists(ImportConfig::cursor())) {
97 $data = file_get_contents(ImportConfig::cursor());
98 $this->cursorValue = unserialize($data);
99 }
100 }
101 return ($this->cursorValue) ? $this->cursorValue : '?';
102 }
103
104 public function writeCursor() {
105 $f = fopen(ImportConfig::cursor(), 'w+');
106 fwrite($f, serialize($this->cursorValue));
107 fclose($f);
108 }
109
110 public function incrementCursor() {
111 $this->cursorValue = $this->cursorValue + 1;
112 $this->writeCursor();
113 }
114
115 }
[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.
-