Merge lp:~tristan-rivoallan/vanilla-miner/vm-599699 into lp:vanilla-miner

Proposed by Tristan Rivoallan
Status: Merged
Merged at revision: 63
Proposed branch: lp:~tristan-rivoallan/vanilla-miner/vm-599699
Merge into: lp:vanilla-miner
Diff against target: 100 lines (+56/-13)
1 file modified
lib/task/minerExpandLinksTask.class.php (+56/-13)
To merge this branch: bzr merge lp:~tristan-rivoallan/vanilla-miner/vm-599699
Reviewer Review Type Date Requested Status
Tristan Rivoallan Approve
Review via email: mp+28920@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Tristan Rivoallan (tristan-rivoallan) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/task/minerExpandLinksTask.class.php'
--- lib/task/minerExpandLinksTask.class.php 2010-06-29 17:22:22 +0000
+++ lib/task/minerExpandLinksTask.class.php 2010-06-30 17:17:27 +0000
@@ -103,16 +103,37 @@
103 $this->logSection('expand', sprintf('[%d] %s - Updating metadata, marking as available', $response->getStatus(), $link->url));103 $this->logSection('expand', sprintf('[%d] %s - Updating metadata, marking as available', $response->getStatus(), $link->url));
104 }104 }
105105
106 // Extract meaningful informations from server response106 // Update link data according to response
107 $header = $response->getHeader();107 $link = $this->updateLink($link, $response);
108 $header = $this->normalizeHeader($header);108 }
109 $link->mime_type = $this->getMimeType($header);109 // Try GET when server answers "405 Method Not Allowed"
110110 elseif (405 == $response->getStatus())
111 // Mark link as available111 {
112 $link->availability = 'available';112 if ($options['progress'])
113113 {
114 // Save link to database114 $this->log(sprintf('[%d] %s', $response->getStatus(), $link->url));
115 $link->replace();115 }
116 else
117 {
118 $this->logSection('expand', sprintf('[%d] %s - Received "Method Not Allowed" error code. Trying GET.', $response->getStatus(), $link->url));
119 }
120
121 $request->setMethod(HTTP_Request2::METHOD_GET);
122 $response = $request->send();
123 if (200 == $response->getStatus())
124 {
125 if ($options['progress'])
126 {
127 $this->log(sprintf('[%d] %s', $response->getStatus(), $link->url));
128 }
129 else
130 {
131 $this->logSection('expand', sprintf('[%d] %s - Updating metadata, marking as available', $response->getStatus(), $link->url));
132 }
133
134 // Update link data according to response
135 $link = $this->updateLink($link, $response);
136 }
116 }137 }
117 else138 else
118 {139 {
@@ -134,7 +155,6 @@
134 );155 );
135 }156 }
136 $link->availability = 'unavailable';157 $link->availability = 'unavailable';
137 $link->replace();
138 }158 }
139 }159 }
140 catch (HTTP_Request2_Exception $e)160 catch (HTTP_Request2_Exception $e)
@@ -148,9 +168,11 @@
148 $this->logSection('expand', sprintf('[ERR] Received exception with message "%s" for link "%s" - Marking as unavailable.', $e->getMessage(), $link->url), null, 'ERROR');168 $this->logSection('expand', sprintf('[ERR] Received exception with message "%s" for link "%s" - Marking as unavailable.', $e->getMessage(), $link->url), null, 'ERROR');
149 }169 }
150 $link->availability = 'unavailable';170 $link->availability = 'unavailable';
151 $link->replace();
152 }171 }
153172
173 // Save link to database
174 $link->replace();
175
154 // Update progress bar176 // Update progress bar
155 if ($options['progress'])177 if ($options['progress'])
156 {178 {
@@ -210,4 +232,25 @@
210232
211 return $mime_type;233 return $mime_type;
212 }234 }
213}
214\ No newline at end of file235\ No newline at end of file
236
237 /**
238 * Updates link according to supplied (successful) response
239 *
240 * @param Link $link
241 * @param HTTP_Request2_Response $response
242 *
243 * @return Link $link
244 */
245 private function updateLink(Link $link, HTTP_Request2_Response $response)
246 {
247 // Extract meaningful informations from server response
248 $header = $response->getHeader();
249 $header = $this->normalizeHeader($header);
250 $link->mime_type = $this->getMimeType($header);
251
252 // Mark link as available
253 $link->availability = 'available';
254
255 return $link;
256 }
257}

Subscribers

People subscribed via source and target branches

to all changes: