Skip to content

Commit

Permalink
Merge pull request #6 from oveleon/develop
Browse files Browse the repository at this point in the history
Updated settings for modules and added elapsed time
  • Loading branch information
eki89 authored Jan 28, 2022
2 parents aa8b90d + b13c51d commit af9c072
Show file tree
Hide file tree
Showing 23 changed files with 2,319 additions and 2,081 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

---

> Working with **Contao 4.9** and up to **Contao 4.12** (PHP ^7.2 and PHP 8)
> Working with **Contao 4.9** and up to **Contao 4.12** (PHP ^7.4 and PHP 8)
---

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
],
"require": {
"php": "^7.2 || ^8.0",
"php": "^7.4 || ^8.0",
"contao/core-bundle":"^4.9"
},
"require-dev": {
Expand All @@ -39,7 +39,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
"dev-master": "1.2.x-dev"
},
"contao-manager-plugin": "Oveleon\\ContaoRecommendationBundle\\ContaoManager\\Plugin"
}
Expand Down
232 changes: 116 additions & 116 deletions src/Resources/contao/classes/Recommendation.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,120 +22,120 @@
*/
class Recommendation extends Backend
{
/**
* Purge recommendations that have not been activated within 24 hours
*/
public function purgeRecommendations()
{
$objRecommendation = RecommendationModel::findExpiredRecommendations();

if ($objRecommendation === null)
{
return;
}

while ($objRecommendation->next())
{
$objRecommendation->delete();
}

// Add a log entry
$logger = System::getContainer()->get('monolog.logger.contao');
$logger->log(LogLevel::INFO, 'Purged the unactivated recommendations', array('contao' => new ContaoContext(__METHOD__, TL_CRON)));
}

/**
* Add Recommendations to the indexer
*
* @param array $arrPages
* @param integer $intRoot
* @param boolean $blnIsSitemap
*
* @return array
*/
public function getSearchablePages($arrPages, $intRoot=0, $blnIsSitemap=false)
{
$arrRoot = array();

if ($intRoot > 0)
{
$arrRoot = $this->Database->getChildRecords($intRoot, 'tl_page');
}

$arrProcessed = array();
$time = time();

// Get all categories
$objRecommendationArchive = RecommendationArchiveModel::findByProtected('');

// Walk through each archive
if ($objRecommendationArchive !== null)
{
while($objRecommendationArchive->next())
{
// Skip archives without a target page
if (!$objRecommendationArchive->jumpTo)
{
continue;
}

// Skip archives outside the root nodes
if (!empty($arrRoot) && !\in_array($objRecommendationArchive->jumpTo, $arrRoot))
{
continue;
}

// Get the URL of the jumpTo page
if (!isset($arrProcessed[$objRecommendationArchive->jumpTo]))
{
$objParent = PageModel::findWithDetails($objRecommendationArchive->jumpTo);

// The target page does not exist
if ($objParent === null)
{
continue;
}

// The target page has not been published
if (!$objParent->published || ($objParent->start && $objParent->start > $time) || ($objParent->stop && $objParent->stop <= $time))
{
continue;
}

if($blnIsSitemap)
{
// The target page is protected
if ($objParent->protected)
{
continue;
}

// the target page is exempt from the sitemap
if ($objParent->robots == 'noindex,nofollow')
{
continue;
}
}

// Generate the URL
$arrProcessed[$objRecommendationArchive->jumpTo] = $objParent->getAbsoluteUrl(Config::get('useAutoItem') ? '/%s' : '/items/%s');
}

$strUrl = $arrProcessed[$objRecommendationArchive->jumpTo];

// Get the items
$objItems = RecommendationModel::findPublishedByPid($objRecommendationArchive->id);

if($objItems !== null)
{
while ($objItems->next())
{
$arrPages[] = sprintf(preg_replace('/%(?!s)/', '%%', $strUrl), ($objItems->alias ?: $objItems->id));
}
}
}
}

return $arrPages;
}
/**
* Purge recommendations that have not been activated within 24 hours
*/
public function purgeRecommendations()
{
$objRecommendation = RecommendationModel::findExpiredRecommendations();

if ($objRecommendation === null)
{
return;
}

while ($objRecommendation->next())
{
$objRecommendation->delete();
}

// Add a log entry
$logger = System::getContainer()->get('monolog.logger.contao');
$logger->log(LogLevel::INFO, 'Purged the unactivated recommendations', array('contao' => new ContaoContext(__METHOD__, TL_CRON)));
}

/**
* Add Recommendations to the indexer
*
* @param array $arrPages
* @param integer $intRoot
* @param boolean $blnIsSitemap
*
* @return array
*/
public function getSearchablePages($arrPages, $intRoot=0, $blnIsSitemap=false)
{
$arrRoot = array();

if ($intRoot > 0)
{
$arrRoot = $this->Database->getChildRecords($intRoot, 'tl_page');
}

$arrProcessed = array();
$time = time();

// Get all categories
$objRecommendationArchive = RecommendationArchiveModel::findByProtected('');

// Walk through each archive
if ($objRecommendationArchive !== null)
{
while($objRecommendationArchive->next())
{
// Skip archives without a target page
if (!$objRecommendationArchive->jumpTo)
{
continue;
}

// Skip archives outside the root nodes
if (!empty($arrRoot) && !\in_array($objRecommendationArchive->jumpTo, $arrRoot))
{
continue;
}

// Get the URL of the jumpTo page
if (!isset($arrProcessed[$objRecommendationArchive->jumpTo]))
{
$objParent = PageModel::findWithDetails($objRecommendationArchive->jumpTo);

// The target page does not exist
if ($objParent === null)
{
continue;
}

// The target page has not been published
if (!$objParent->published || ($objParent->start && $objParent->start > $time) || ($objParent->stop && $objParent->stop <= $time))
{
continue;
}

if($blnIsSitemap)
{
// The target page is protected
if ($objParent->protected)
{
continue;
}

// the target page is exempt from the sitemap
if ($objParent->robots == 'noindex,nofollow')
{
continue;
}
}

// Generate the URL
$arrProcessed[$objRecommendationArchive->jumpTo] = $objParent->getAbsoluteUrl(Config::get('useAutoItem') ? '/%s' : '/items/%s');
}

$strUrl = $arrProcessed[$objRecommendationArchive->jumpTo];

// Get the items
$objItems = RecommendationModel::findPublishedByPid($objRecommendationArchive->id);

if($objItems !== null)
{
while ($objItems->next())
{
$arrPages[] = sprintf(preg_replace('/%(?!s)/', '%%', $strUrl), ($objItems->alias ?: $objItems->id));
}
}
}
}

return $arrPages;
}
}
Loading

0 comments on commit af9c072

Please sign in to comment.