Skip to content

Commit

Permalink
NEW: Fixes deviateltd#8 SS4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Russell Michell committed Dec 21, 2017
1 parent 57e68e2 commit 5600acf
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
12 changes: 11 additions & 1 deletion README.md
Expand Up @@ -9,4 +9,14 @@ immediately, will likely be more apparent on busy, content-heavy sites, who's co
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).
sitemap, you might consider the standard [Google SiteMaps Module](https://github.com/silverstripe-labs/silverstripe-googlesitemaps).

## Installation

### SilverStripe 4

composer require deviateltd/googlesitemapautoupdate: 2.0.x

### SilverStripe 4

composer require deviateltd/googlesitemapautoupdate: 1.0.x
2 changes: 1 addition & 1 deletion _config.php
@@ -1,5 +1,5 @@
<?php
/**
* @author Deviate Ltd 2014-2015 http://www.deviate.net.nz
* @author Deviate Ltd 2014-2017 http://www.deviate.net.nz
* @package silverstripe-googlesitemapautoupdate
*/
4 changes: 2 additions & 2 deletions _config/googlesitemapautoupdate.yml
Expand Up @@ -5,6 +5,6 @@ After:
- 'cms/*'
- 'queuedjobs/*'
---
SiteTree:
SilverStripe\CMS\Model\SiteTree:
extensions:
- SitemapUpdater
- DeviateLtd\GoogleSitemapAutoUpdater\Model\SitemapUpdater
25 changes: 18 additions & 7 deletions code/extensions/SitemapUpdater.php
@@ -1,4 +1,14 @@
<?php

namespace DeviateLtd\GoogleSitemapAutoUpdater\Model;

use SilverStripe\CMS\Model\SiteTreeExtension;
use Symbiote\QueuedJobs\Services\AbstractQueuedJob;
use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor;
use Symbiote\QueuedJobs\Services\QueuedJob,
use Symbiote\QueuedJobs\Services\QueuedJobService;
use Symbiote\QueuedJobs\Jobs\GenerateGoogleSitemapJob;

/**
*
* A simple {@link SiteTreeExtension} that invokes a {@link QueuedJob} to
Expand All @@ -19,14 +29,14 @@ class SitemapUpdater extends SiteTreeExtension
*/
public function onAfterPublish(&$original)
{
if (!class_exists('AbstractQueuedJob')) {
if (!class_exists(AbstractQueuedJob::class)) {
return;
}

// Get all "running" GenerateGoogleSitemapJob's
$list = QueuedJobDescriptor::get()->filter(array(
'Implementation'=> 'GenerateGoogleSitemapJob',
'JobStatus' => array(QueuedJob::STATUS_INIT, QueuedJob::STATUS_RUN)
'Implementation'=> GenerateGoogleSitemapJob::class,
'JobStatus' => [QueuedJob::STATUS_INIT, QueuedJob::STATUS_RUN]
));

$existingJob = $list ? $list->first() : null;
Expand All @@ -36,8 +46,8 @@ public function onAfterPublish(&$original)
$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),
'Implementation'=> GenerateGoogleSitemapJob::class,
'JobStatus' => [QueuedJob::STATUS_NEW],
));
$list = $list->sort('ID', 'ASC');

Expand All @@ -46,6 +56,7 @@ public function onAfterPublish(&$original)
$existingJob = $list->first();
$existingJob->StartAfter = date('Y-m-d H:i:s');
$existingJob->write();

return;
}

Expand All @@ -60,15 +71,15 @@ public function onAfterPublish(&$original)
* Broken
*/
$list = QueuedJobDescriptor::get()->filter(array(
'Implementation' => 'GenerateGoogleSitemapJob',
'Implementation' => GenerateGoogleSitemapJob::class,
));

if ($list && $list->count()) {
$list->removeAll();
}

$job = new GenerateGoogleSitemapJob();
singleton('QueuedJobService')->queueJob($job);
singleton(QueuedJobService::class)->queueJob($job);
}
}
}
10 changes: 5 additions & 5 deletions composer.json
@@ -1,7 +1,7 @@
{
"name": "deviateltd/silverstripe-googlesitemapautoupdate",
"description": "Creates a Google sitemap.xml and auto-updates it whenever a page published.",
"type": "silverstripe-module",
"type": "silverstripe-vendormodule",
"keywords": ["sitemap", "google", "auto", "update"],
"authors": [
{
Expand All @@ -10,13 +10,13 @@
},
{
"name": "Russell Michell",
"email": "russell.michell@deviate.net.nz"
"email": "russellmichell@catalyst.net.nz"
}
],
"require": {
"composer/installers": "*",
"silverstripe/cms": ">=3.1",
"silverstripe/framework": ">=3.1",
"silverstripe/queuedjobs": ">=2.3.1"
"silverstripe/cms": "4.0.x-dev",
"silverstripe/framework": "4.0.x-dev",
"silverstripe/queuedjobs": "~4.0.5"
}
}

0 comments on commit 5600acf

Please sign in to comment.