Created
September 21, 2010 14:36
-
-
Save co3k/589766 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'Zend/Loader.php'; | |
Zend_Loader::loadClass('Zend_Gdata'); | |
Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); | |
Zend_Loader::loadClass('Zend_Gdata_Spreadsheets'); | |
require_once 'config.php'; | |
define('SPREADSHEET_ID', 'tPPseSNcB7ho4tho-2aB4vg'); | |
//define('SPREADSHEET_ID', 'tiG3IKq6Xgfj9lnabbJhMWg'); | |
define('SPREADSHEET_ENTRY_URL', 'http://spreadsheets.google.com/feeds/spreadsheets/'.SPREADSHEET_ID); | |
define('REDMINE_37_ID', 111); | |
function betaIds() | |
{ | |
return array( | |
'beta4' => 112, | |
'beta5' => 122, | |
'beta6' => 123, | |
); | |
} | |
function getIssues($id) | |
{ | |
$redmine_version_url = 'http://redmine.openpne.jp/versions/show/'.$id; | |
$document = new DOMDocument(); | |
$document->loadHTMLFile($redmine_version_url); | |
$ticket_list = $document->getElementsByTagName('fieldset')->item(1)->getElementsByTagName('li'); | |
$issues = array(); | |
foreach ($ticket_list as $t) | |
{ | |
if (false !== strpos($t->nodeValue, 'Bug') || false !== strpos($t->nodeValue, 'Backport')) | |
{ | |
preg_match('/^.+?#(?P<ticket_id>[0-9]+):(?P<ticket_subject>.*)$/', $t->nodeValue, $matches); | |
$ticket_info = simplexml_load_file('http://redmine.openpne.jp/issues/'.$matches['ticket_id'].'.xml'); | |
$priority = $ticket_info->priority->attributes(); | |
$issues[] = array( | |
'id' => $matches['ticket_id'], | |
'subject' => $matches['ticket_subject'], | |
'priority' => $priority['name'], | |
); | |
} | |
} | |
return $issues; | |
} | |
function searchSubject($subject, $betas) | |
{ | |
foreach ($betas as $version => $issues) | |
{ | |
foreach ($issues as $k => $v) | |
{ | |
if ($subject === $v['subject']) | |
{ | |
return array($version, $v['id']); | |
} | |
} | |
} | |
return false; | |
} | |
$httpClient = new Zend_Gdata_HttpClient(); | |
$httpClient->setAdapter('Zend_Http_Client_Adapter_Curl'); | |
$client = Zend_Gdata_ClientLogin::getHttpClient($username, $password, Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME, $httpClient); | |
$service = new Zend_Gdata_Spreadsheets($client); | |
$rows = getIssues(REDMINE_37_ID); | |
var_dump('Process '.count($rows).' issues'); | |
$betaids = betaIds(); | |
$betas = array( | |
'beta4' => getIssues($betaids['beta4']), | |
'beta5' => getIssues($betaids['beta5']), | |
'beta6' => getIssues($betaids['beta6']), | |
); | |
foreach ($rows as $k => $v) | |
{ | |
if (!($k % 10)) | |
{ | |
var_dump($k); | |
} | |
try | |
{ | |
$q = new Zend_Gdata_Spreadsheets_ListQuery(); | |
$q->setSpreadsheetKey(SPREADSHEET_ID) | |
->setSpreadsheetQuery('id='.$v['id']); | |
$entries = $service->getListFeed($q); | |
if ((string)$entries->getTotalResults()) | |
{ | |
var_dump($v['id'].'あるし'); | |
$entry = $entries[0]; | |
} | |
else | |
{ | |
$entry = $service->insertRow(array( | |
'id' => $v['id'], | |
'original' => $v['subject'], | |
'priority' => $v['priority'], | |
'backport' => '', | |
'version' => '', | |
), SPREADSHEET_ID); | |
var_dump($v['id'].'追加だし'); | |
} | |
$newRow = array( | |
'id' => (string)$entry->getCustomByName('id'), | |
'original' => (string)$entry->getCustomByName('original'), | |
'priority' => $v['priority'], | |
'backport' => '', | |
'version' => '', | |
); | |
if ($hit = searchSubject($v['subject'], $betas)) | |
{ | |
$newRow['backport'] = 'http://redmine.openpne.jp/issues/'.$hit[1]; | |
$newRow['version'] = $hit[0]; | |
} | |
$entry = $service->updateRow($entry, $newRow); | |
} catch (Zend_Gdata_App_HttpException $e) | |
{ | |
$rows[] = $v; | |
var_dump($v['id'].'は失敗したのであとで再試行'); | |
} | |
usleep(500000); // 0.5 sec | |
} | |
var_dump('おわた'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment