/** * Store each crawl result to database * * @param String $requestedUrl the requested url * @param String $refererUrl the lead url * @param Integer $referPageId the lead url page id * @param String $requestedUrlText the requested url text * * @return null */ public function storeUrlInfos($requestedUrl, $refererUrl, $referPageId, $requestedUrlText) { global $_CONFIG; $urlStatus = $this->getUrlStatus($requestedUrl); //Check the requested url is internal or not $isInternalLink = $this->getController('Url')->isInternalUrl($requestedUrl); //find the entry name, module name, action and parameter $moduleName = $moduleAction = $moduleParams = ''; if ($isInternalLink) { list($entryTitle, $moduleName, $moduleAction, $moduleParams) = $this->getModuleDetails($requestedUrl, $refererUrl); } else { $objRefererUrl = $this->getPageByUrl($refererUrl); $entryTitle = $objRefererUrl ? $objRefererUrl->getTitle() : ''; } //Get the backend referer url by referPageId if (!empty($referPageId)) { $backendReferUrl = ASCMS_PROTOCOL . '://' . $_CONFIG['domainUrl'] . ASCMS_PATH_OFFSET . '/cadmin/index.php?cmd=ContentManager&page=' . $referPageId; } $link = $this->linkRepo->findOneBy(array('requestedPath' => $requestedUrl)); if ($link && $link->getRefererPath() == $refererUrl && $link->getLinkStatusCode() != $urlStatus) { $this->copyLinkToHistory($link); } $persist = false; if (!$link) { $link = new \Cx\Core_Modules\LinkManager\Model\Entity\Link(); $persist = true; } $link->setLang($this->langId); $link->setBrokenLinkText($requestedUrlText); $link->setRefererPath($refererUrl); $link->setRequestedPath($requestedUrl); $link->setLeadPath($backendReferUrl); $link->setEntryTitle($entryTitle); $link->setDetectedTime(new \DateTime('now')); $link->setUpdatedBy(0); $link->setLinkStatusCode($urlStatus); $link->setFlagStatus($urlStatus == 200 ? 1 : 0); $link->setLinkRecheck(0); $link->setRequestedLinkType($isInternalLink ? 'internal' : 'external'); $link->setLinkStatus(0); if ($persist) { $this->em->persist($link); } $this->em->flush(); }
/** * Recheck all the links in the page and update those links status code * * @param \Cx\Core_Modules\LinkManager\Model\Entity\Link $link Parent link obejct * @param array $subLinks Links in the parent link * * @return null */ public function recheckPage(\Cx\Core_Modules\LinkManager\Model\Entity\Link $link, $subLinks = array()) { //If there is no recheck links then return if (!$subLinks) { return; } foreach ($subLinks as $subLinkUrl => $subLinkName) { //If the link already exists then proceed with next link if ($this->linkRepository->getLinkByPath($subLinkUrl)) { continue; } $urlStatus = $this->getUrlStatus($subLinkUrl); $isInternalLink = $this->getController('Url')->isInternalUrl($subLinkUrl); $subLink = new \Cx\Core_Modules\LinkManager\Model\Entity\Link(); $subLink->setLang($link->getLang()); $subLink->setRefererPath($link->getRefererPath()); $subLink->setLeadPath($link->getLeadPath()); $subLink->setEntryTitle($link->getEntryTitle()); $subLink->setDetectedTime($link->getDetectedTime()); $subLink->setUpdatedBy(\FWUser::getFWUserObject()->objUser->getId()); $subLink->setBrokenLinkText($subLinkName); $subLink->setRequestedPath($subLinkUrl); $subLink->setLinkStatusCode($urlStatus); $subLink->setFlagStatus($urlStatus == 200 ? 1 : 0); $subLink->setLinkRecheck(1); $subLink->setRequestedLinkType($isInternalLink ? 'internal' : 'external'); $subLink->setLinkStatus(1); $this->em->persist($subLink); } $this->em->flush(); }