1 | <?php |
||
27 | class Fetcher { |
||
28 | |||
29 | const DEFAULT_BASE_URL = 'https://updates.owncloud.com/server/'; |
||
30 | |||
31 | /** |
||
32 | * @var Locator $locator |
||
33 | */ |
||
34 | protected $locator; |
||
35 | |||
36 | /** |
||
37 | * @var ConfigReader $configReader |
||
38 | */ |
||
39 | protected $configReader; |
||
40 | |||
41 | /** |
||
42 | * @var Client $httpClient |
||
43 | */ |
||
44 | protected $httpClient; |
||
45 | protected $requiredFeedEntries = [ |
||
46 | 'version', |
||
47 | 'versionstring', |
||
48 | 'url' |
||
49 | ]; |
||
50 | |||
51 | /** |
||
52 | * Constructor |
||
53 | * |
||
54 | * @param Client $httpClient |
||
55 | * @param Locator $locator |
||
56 | * @param ConfigReader $configReader |
||
57 | */ |
||
58 | 3 | public function __construct(Client $httpClient, Locator $locator, ConfigReader $configReader){ |
|
59 | 3 | $this->httpClient = $httpClient; |
|
60 | 3 | $this->locator = $locator; |
|
61 | 3 | $this->configReader = $configReader; |
|
62 | 3 | } |
|
63 | |||
64 | /** |
||
65 | * Download new ownCloud package |
||
66 | * @param Feed $feed |
||
67 | * @param Callable $onProgress |
||
68 | * @throws \UnexpectedValueException |
||
69 | */ |
||
70 | public function getOwncloud(Feed $feed, callable $onProgress){ |
||
71 | if ($feed->isValid()){ |
||
72 | $downloadPath = $this->getBaseDownloadPath($feed); |
||
73 | if (!is_writable(dirname($downloadPath))){ |
||
74 | throw new \Exception(dirname($downloadPath) . ' is not writable.'); |
||
75 | } |
||
76 | $url = $feed->getUrl(); |
||
77 | $request = $this->httpClient->createRequest( |
||
78 | 'GET', |
||
79 | $url, |
||
80 | [ |
||
81 | 'save_to' => $downloadPath, |
||
82 | 'timeout' => 600 |
||
83 | ] |
||
84 | ); |
||
85 | $request->getEmitter()->on('progress', $onProgress); |
||
86 | $response = $this->httpClient->send($request); |
||
87 | $this->validateResponse($response); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Produce a local path to save the package to |
||
93 | * @param Feed $feed |
||
94 | * @return string |
||
95 | */ |
||
96 | public function getBaseDownloadPath(Feed $feed){ |
||
100 | |||
101 | /** |
||
102 | * Get md5 sum for the package |
||
103 | * @param Feed $feed |
||
104 | * @return string |
||
105 | */ |
||
106 | public function getMd5(Feed $feed){ |
||
112 | |||
113 | /** |
||
114 | * Read update feed for new releases |
||
115 | * @return Feed |
||
116 | */ |
||
117 | 3 | public function getFeed(){ |
|
135 | |||
136 | 3 | public function getUpdateChannel(){ |
|
137 | 3 | $channel = $this->configReader->getByPath('apps.core.OC_Channel'); |
|
144 | |||
145 | /** |
||
146 | * Produce complete feed URL |
||
147 | * @return string |
||
148 | */ |
||
149 | 3 | protected function getFeedUrl(){ |
|
167 | |||
168 | /** |
||
169 | * Get URL content |
||
170 | * @param string $url |
||
171 | * @return string |
||
172 | * @throws \UnexpectedValueException |
||
173 | */ |
||
174 | 3 | protected function download($url){ |
|
179 | |||
180 | /** |
||
181 | * Check if request was successful |
||
182 | * @param \GuzzleHttp\Message\ResponseInterface $response |
||
183 | * @throws \UnexpectedValueException |
||
184 | */ |
||
185 | 3 | protected function validateResponse($response){ |
|
195 | |||
196 | } |
||
197 |