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
1=== modified file 'lib/task/minerExpandLinksTask.class.php'
2--- lib/task/minerExpandLinksTask.class.php 2010-06-29 17:22:22 +0000
3+++ lib/task/minerExpandLinksTask.class.php 2010-06-30 17:17:27 +0000
4@@ -103,16 +103,37 @@
5 $this->logSection('expand', sprintf('[%d] %s - Updating metadata, marking as available', $response->getStatus(), $link->url));
6 }
7
8- // Extract meaningful informations from server response
9- $header = $response->getHeader();
10- $header = $this->normalizeHeader($header);
11- $link->mime_type = $this->getMimeType($header);
12-
13- // Mark link as available
14- $link->availability = 'available';
15-
16- // Save link to database
17- $link->replace();
18+ // Update link data according to response
19+ $link = $this->updateLink($link, $response);
20+ }
21+ // Try GET when server answers "405 Method Not Allowed"
22+ elseif (405 == $response->getStatus())
23+ {
24+ if ($options['progress'])
25+ {
26+ $this->log(sprintf('[%d] %s', $response->getStatus(), $link->url));
27+ }
28+ else
29+ {
30+ $this->logSection('expand', sprintf('[%d] %s - Received "Method Not Allowed" error code. Trying GET.', $response->getStatus(), $link->url));
31+ }
32+
33+ $request->setMethod(HTTP_Request2::METHOD_GET);
34+ $response = $request->send();
35+ if (200 == $response->getStatus())
36+ {
37+ if ($options['progress'])
38+ {
39+ $this->log(sprintf('[%d] %s', $response->getStatus(), $link->url));
40+ }
41+ else
42+ {
43+ $this->logSection('expand', sprintf('[%d] %s - Updating metadata, marking as available', $response->getStatus(), $link->url));
44+ }
45+
46+ // Update link data according to response
47+ $link = $this->updateLink($link, $response);
48+ }
49 }
50 else
51 {
52@@ -134,7 +155,6 @@
53 );
54 }
55 $link->availability = 'unavailable';
56- $link->replace();
57 }
58 }
59 catch (HTTP_Request2_Exception $e)
60@@ -148,9 +168,11 @@
61 $this->logSection('expand', sprintf('[ERR] Received exception with message "%s" for link "%s" - Marking as unavailable.', $e->getMessage(), $link->url), null, 'ERROR');
62 }
63 $link->availability = 'unavailable';
64- $link->replace();
65 }
66
67+ // Save link to database
68+ $link->replace();
69+
70 // Update progress bar
71 if ($options['progress'])
72 {
73@@ -210,4 +232,25 @@
74
75 return $mime_type;
76 }
77-}
78\ No newline at end of file
79+
80+ /**
81+ * Updates link according to supplied (successful) response
82+ *
83+ * @param Link $link
84+ * @param HTTP_Request2_Response $response
85+ *
86+ * @return Link $link
87+ */
88+ private function updateLink(Link $link, HTTP_Request2_Response $response)
89+ {
90+ // Extract meaningful informations from server response
91+ $header = $response->getHeader();
92+ $header = $this->normalizeHeader($header);
93+ $link->mime_type = $this->getMimeType($header);
94+
95+ // Mark link as available
96+ $link->availability = 'available';
97+
98+ return $link;
99+ }
100+}

Subscribers

People subscribed via source and target branches

to all changes: