4 class Repository_LinkbackReceiver
5 implements \PEAR2\Services\Linkback\Server\Callback\IStorage
9 public function __construct($repo)
14 public function storeLinkback(
15 $target, $source, $sourceBody, \HTTP_Request2_Response $res
21 $hp = new HtmlParser();
22 $ok = $hp->extractGitUrls($source, $sourceBody);
24 //failed to extract git URL from linkback source
25 //FIXME: send exception
30 $ci = $this->repo->getConnectionInfo();
31 $forks = $ci->getForks();
33 $remoteCloneUrl = $remoteTitle = null;
34 $arRemoteCloneUrls = array();
35 $arGitUrls = $hp->getGitUrls();
36 foreach ($arGitUrls as $remoteTitle => $arUrls) {
37 foreach ($arUrls as $remoteCloneUrl) {
38 $arRemoteCloneUrls[$remoteCloneUrl] = $remoteTitle;
42 $remoteid = 'fork-' . uniqid();
43 //check if we already know this remote
44 foreach ($forks as $remote) {
45 if (isset($arRemoteCloneUrls[$remote->getCloneUrl()])
46 || $source == $remote->getWebURL(true)
48 $remoteid = $remote->getName();
53 if ($this->isLocalWebUrl($source)) {
54 //convert both web and clone url to local urls
57 $vc = $this->repo->getVc();
58 $vc->getCommand('config')
59 ->addArgument('remote.' . $remoteid . '.homepage')
60 ->addArgument($source)
62 if ($remoteTitle !== null) {
63 $vc->getCommand('config')
64 ->addArgument('remote.' . $remoteid . '.title')
65 ->addArgument($remoteTitle)
68 if ($remoteCloneUrl !== null) {
69 $vc->getCommand('config')
70 ->addArgument('remote.' . $remoteid . '.url')
71 ->addArgument($remoteCloneUrl)
76 protected function isLocalWebUrl($url)
78 $base = Tools::fullUrl();
79 if (substr($url, 0, strlen($base)) != $base) {
84 $remainder = substr($url, strlen($base));
85 //FIXME: check if it exists