1 | <?php |
||
11 | class UpdaterData |
||
12 | { |
||
13 | const DOWNLOAD_DIR = "downloads/"; |
||
14 | const TIMEZONE_FILE_NAME = "timezones"; |
||
15 | const REPO_HOST = "https://api.github.com"; |
||
16 | const REPO_USER = "node-geo-tz"; |
||
17 | const REPO_PATH = "/repos/evansiroky/timezone-boundary-builder/releases/latest"; |
||
18 | const GEO_JSON_DEFAULT_URL = "none"; |
||
19 | const GEO_JSON_DEFAULT_NAME = "geojson"; |
||
20 | |||
21 | protected $mainDir = null; |
||
22 | protected $downloadDir = null; |
||
23 | protected $timezonesSourcePath = null; |
||
24 | |||
25 | /** |
||
26 | * UpdaterData constructor. |
||
27 | * @param $dataDirectory |
||
28 | * @throws ErrorException |
||
29 | */ |
||
30 | public function __construct($dataDirectory = null) |
||
39 | |||
40 | /** |
||
41 | * Get complete json response from repo |
||
42 | * @param $url |
||
43 | * @return mixed |
||
44 | */ |
||
45 | protected function getResponse($url) |
||
51 | |||
52 | /** |
||
53 | * Download zip file |
||
54 | * @param $url |
||
55 | * @param string $destinationPath |
||
56 | */ |
||
57 | protected function getZipResponse($url, $destinationPath = "none") |
||
61 | |||
62 | /** |
||
63 | * Get timezones json url |
||
64 | * @param $data |
||
65 | * @return string |
||
66 | */ |
||
67 | protected function getGeoJsonUrl($data) |
||
79 | |||
80 | /** |
||
81 | * Download last version reference repo |
||
82 | */ |
||
83 | protected function downloadLastVersion() |
||
97 | |||
98 | /** |
||
99 | * Unzip data |
||
100 | * @param $filePath |
||
101 | * @return bool |
||
102 | */ |
||
103 | protected function unzipData($filePath) |
||
120 | |||
121 | /** |
||
122 | * Rename downloaded timezones json file |
||
123 | * @return bool |
||
124 | */ |
||
125 | protected function renameTimezoneJson() |
||
140 | |||
141 | /** |
||
142 | * Remove all directories tree in a particular data folder |
||
143 | * @param $path |
||
144 | * @param $validDir |
||
145 | */ |
||
146 | protected function removeData($path, $validDir = null) |
||
170 | |||
171 | /** |
||
172 | * Remove data tree |
||
173 | */ |
||
174 | protected function removeDataTree() |
||
184 | |||
185 | |||
186 | /** |
||
187 | * Remove downloaded data |
||
188 | */ |
||
189 | protected function removeDownloadedData() |
||
194 | |||
195 | /** |
||
196 | * Add folder to zip file |
||
197 | * @param $mainDir |
||
198 | * @param $zip |
||
199 | * @param $exclusiveLength |
||
200 | */ |
||
201 | protected function folderToZip($mainDir, &$zip, $exclusiveLength) |
||
218 | |||
219 | /** |
||
220 | * Compress directory |
||
221 | * @param $sourcePath |
||
222 | * @param $outZipPath |
||
223 | */ |
||
224 | protected function zipDir($sourcePath, $outZipPath) |
||
236 | |||
237 | /** |
||
238 | * Main function that runs all updating process |
||
239 | */ |
||
240 | public function updateData() |
||
258 | } |
||
259 | |||
260 |