Skip to content
Permalink
Browse files

MINOR: Updated README, added more inline comments.

  • Loading branch information...
phptek committed May 6, 2015
1 parent 293554b commit c27a16f205fb58a77ce6b7054633fae8f1306b7a
Showing with 38 additions and 13 deletions.
  1. +10 −2 README.md
  2. +5 −1 _config.php
  3. +23 −10 code/extensions/SitemapUpdater.php
@@ -1,4 +1,12 @@
# SilverStripe Google Sitemap Auto Update

The module goes over and above other similar modules by auto-updating the sitemap.xml
each time an object is published.
This module simply passes the responsibility of physically generating a `sitemap.xml` file
to the [QueuedJobs Module](https://github.com/silverstripe-australia/silverstripe-queuedjobs) which it
does after each write.

The advantage of handing off this procedure to a message queue rather than just doing it
immediately, will likely be more apparent on busy, content-heavy sites, who's content authors
may already experience time-lags when saving content in the CMS.

If you need anything more complicated such as auto-alerting Google of changes to your
sitemap, you might consider the standard [Google SiteMaps Module](https://github.com/silverstripe-labs/silverstripe-googlesitemaps).
@@ -1 +1,5 @@
<?php
<?php
/**
* @author Deviate Ltd 2014-2015 http://www.deviate.net.nz
* @package silverstripe-googlesitemapautoupdate
*/
@@ -1,34 +1,46 @@
<?php
/**
*
* @author Deviate Ltd 2015 http://www.deviate.net.nz
* A simple {@link SiteTreeExtension} that invokes a QueuedJob to
* physically perform the sitemap.xml update.
*
* @author Deviate Ltd 2014-2015 http://www.deviate.net.nz
* @package silverstripe-googlesitemapautoupdate
*/
class SitemapUpdater extends SiteTreeExtension {
/**
*
* @param type $original
* Create a new GenerateGoogleSitemapJob after each CMS write operation.
*
* @param {@inheritdoc}
* @return mixed void | null
*/
public function onAfterPublish(&$original) {
if(!class_exists('AbstractQueuedJob')) {
return;
}
// Get all "running" GenerateGoogleSitemapJob's
$list = QueuedJobDescriptor::get()->filter(array(
'JobStatus' => array(QueuedJob::STATUS_INIT, QueuedJob::STATUS_RUN), //Initialising and Running
'Implementation'=> 'GenerateGoogleSitemapJob',
'JobStatus' => array(QueuedJob::STATUS_INIT, QueuedJob::STATUS_RUN)
));
$existingJob = $list->first();
if ($existingJob && $existingJob->exists()) {
// Doing nothing, there is one job for generating sitemap already running
$existingJob = $list ? $list->first() : null;
if($existingJob && $existingJob->exists()) {
// Do nothing. There's a job for generating the sitemap already running
} else {
$where = '"StartAfter" > \'' . date('Y-m-d H:i:s').'\'';
$list = QueuedJobDescriptor::get()->where($where);
$list = $list->filter(array(
'Implementation'=> 'GenerateGoogleSitemapJob',
'JobStatus' => array(QueuedJob::STATUS_NEW), //New
'JobStatus' => array(QueuedJob::STATUS_NEW),
));
$list = $list->sort('ID', 'ASC');
if ($list && $list->Count()) {
// make it to be executed immediately
if($list && $list->count()) {
// Execute immediately
$existingJob = $list->first();
$existingJob->StartAfter = date('Y-m-d H:i:s');
$existingJob->write();
@@ -46,8 +58,9 @@ public function onAfterPublish(&$original) {
* Broken
*/
$list = QueuedJobDescriptor::get()->filter(array(
'Implementation'=> 'GenerateGoogleSitemapJob',
'Implementation' => 'GenerateGoogleSitemapJob',
));
if($list && $list->count()) {
$list->removeAll();
}

0 comments on commit c27a16f

Please sign in to comment.
You can’t perform that action at this time.