Compare commits

..

3 Commits
3.1.2 ... 2

Author SHA1 Message Date
github-actions b12eee33ed Merge branch '2.4' into 2 2024-03-03 22:44:42 +00:00
Guy Sartorelli 0a17d0c537
Merge pull request #101 from creative-commoners/pulls/2.4/exists
FIX Ensure page has extension before calling method
2024-03-04 11:43:49 +13:00
Steve Boyd 66da923502 FIX Ensure page has extension before calling method 2024-02-29 14:05:44 +13:00
9 changed files with 60 additions and 37 deletions

View File

@ -1,10 +1,10 @@
name: Keepalive
on:
# At 9:45 PM UTC, on day 18 of the month
schedule:
- cron: '45 21 18 * *'
workflow_dispatch:
# The 8th of every month at 11:50am UTC
schedule:
- cron: '50 11 8 * *'
jobs:
keepalive:

View File

@ -1,17 +0,0 @@
name: Merge-up
on:
# At 11:10 AM UTC, only on Thursday
schedule:
- cron: '10 11 * * 4'
workflow_dispatch:
jobs:
merge-up:
name: Merge-up
# Only run cron on the silverstripe account
if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule')
runs-on: ubuntu-latest
steps:
- name: Merge-up
uses: silverstripe/gha-merge-up@v1

12
.upgrade.yml Normal file
View File

@ -0,0 +1,12 @@
mappings:
VersionFeed: SilverStripe\VersionFeed\VersionFeed
VersionFeed_Controller: SilverStripe\VersionFeed\VersionFeedController
VersionFeedSiteConfig: SilverStripe\VersionFeed\VersionFeedSiteConfig
CachedContentFilter: SilverStripe\VersionFeed\Filters\CachedContentFilter
ContentFilter: SilverStripe\VersionFeed\Filters\ContentFilter
RateLimitFilter: SilverStripe\VersionFeed\Filters\RateLimitFilter
\VersionFeed\Filters\CachedContentFilter: SilverStripe\VersionFeed\Filters\CachedContentFilter
\VersionFeed\Filters\ContentFilter: SilverStripe\VersionFeed\Filters\ContentFilter
\VersionFeed\Filters\RateLimitFilter: SilverStripe\VersionFeed\Filters\RateLimitFilter
VersionFeedFunctionalTest: SilverStripe\VersionFeed\Tests\VersionFeedFunctionalTest
VersionFeedTest: SilverStripe\VersionFeed\Tests\VersionFeedTest

View File

@ -7,11 +7,15 @@
The module creates an RSS feed on each page with their change history, as well as one for the entire site.
## Requirements
* Silverstripe ^4
**Note:** For a Silverstripe 3.x compatible version, please use [the 1.x release line](https://github.com/silverstripe/silverstripe-versionfeed/tree/1.2).
## Installation
```sh
composer require silverstripe/versionfeed
```
Install with composer by running `composer require silverstripe/versionfeed` in the root of your Silverstripe project.
## Usage

View File

@ -16,14 +16,14 @@
}
],
"require": {
"php": "^8.1",
"silverstripe/cms": "^5",
"silverstripe/versioned": "^2",
"silverstripe/siteconfig": "^5"
"php": "^7.4 || ^8.0",
"silverstripe/cms": "^4",
"silverstripe/versioned": "^1",
"silverstripe/siteconfig": "^4"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"squizlabs/php_codesniffer": "^3"
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.0"
},
"autoload": {
"psr-4": {
@ -33,4 +33,4 @@
},
"minimum-stability": "dev",
"prefer-stable": true
}
}

View File

@ -1,4 +1,4 @@
Copyright (c) 2017, Silverstripe Limited
Copyright (c) 2017, SilverStripe Limited
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

View File

@ -2,6 +2,7 @@
namespace SilverStripe\VersionFeed;
use SilverStripe\Dev\Deprecation;
use SilverStripe\CMS\Model\SiteTreeExtension;
use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\CheckboxField;
@ -11,7 +12,7 @@ use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\View\Parsers\HtmlDiff;
use SilverStripe\View\Parsers\Diff;
use SilverStripe\CMS\Model\SiteTree;
class VersionFeed extends SiteTreeExtension
@ -79,7 +80,7 @@ class VersionFeed extends SiteTreeExtension
$qLimit = (int)$limit + 1;
$versions = $this->owner->Versions(
"\"WasPublished\"='1' AND \"CanViewType\" IN ('Anyone', 'Inherit') $offset",
"\"LastEdited\" DESC, \"ID\" DESC",
"\"SiteTree\".\"LastEdited\" DESC, \"SiteTree\".\"ID\" DESC",
$qLimit
);
@ -94,7 +95,7 @@ class VersionFeed extends SiteTreeExtension
if (isset($previous)) {
// Produce the diff fields for use in the template.
if ($version->Title != $previous->Title) {
$diffTitle = HtmlDiff::compareHTML($version->Title ?? '', $previous->Title ?? '');
$diffTitle = Diff::compareHTML($version->Title, $previous->Title);
$version->DiffTitle = DBField::create_field('HTMLText', null);
$version->DiffTitle->setValue(
@ -107,7 +108,7 @@ class VersionFeed extends SiteTreeExtension
}
if ($version->Content != $previous->Content) {
$diffContent = HtmlDiff::compareHTML($version->Content ?? '', $previous->Content ?? '');
$diffContent = Diff::compareHTML($version->Content, $previous->Content);
$version->DiffContent = DBField::create_field('HTMLText', null);
$version->DiffContent->setValue('<div>'.$diffContent.'</div>');
@ -168,6 +169,26 @@ class VersionFeed extends SiteTreeExtension
return null;
}
/**
* Compile a list of changes to the current page, excluding non-published and explicitly secured versions.
*
* @deprecated 2.0.0 Use VersionFeed::getDiffList() instead
*
* @param int $highestVersion Top version number to consider.
* @param boolean $fullHistory Set to true to get the full change history, set to false for a single diff.
* @param int $limit Limit to the amount of items returned.
*
* @returns ArrayList List of cleaned records.
*/
public function getDiffedChanges($highestVersion = null, $fullHistory = true, $limit = 100)
{
Deprecation::notice('2.0.0', 'Use VersionFeed::getDiffList() instead');
return $this->getDiffList(
$highestVersion,
$fullHistory ? $limit : 1
);
}
public function updateSettingsFields(FieldList $fields)
{
if (!$this->owner->config()->get('changes_enabled')) {
@ -203,6 +224,7 @@ class VersionFeed extends SiteTreeExtension
public function getSiteRSSLink()
{
// TODO: This link should be from the homepage, not this page.
if (Config::inst()->get(get_class(), 'allchanges_enabled')
&& SiteConfig::current_site_config()->AllChangesEnabled
) {

View File

@ -114,6 +114,7 @@ class VersionFeedController extends Extension
AND ("PublicHistory" IS NULL OR "PublicHistory" = \'1\')
ORDER BY "LastEdited" DESC LIMIT ' . $limit);
$lastChange = $latestChanges->record();
$latestChanges->rewind();
if ($lastChange) {
// Cache the diffs to remove DOS possibility.
@ -190,6 +191,7 @@ class VersionFeedController extends Extension
{
if (!Config::inst()->get(VersionFeed::class, 'allchanges_enabled')
|| !SiteConfig::current_site_config()->AllChangesEnabled
|| !method_exists($this->owner, 'getSiteRSSLink')
) {
return;
}

View File

@ -175,7 +175,7 @@ class VersionFeedFunctionalTest extends FunctionalTest
$titles = array_map(function ($item) {
return (string)$item->title;
}, $xml->xpath('//item') ?? []);
// TODO Unclear if this should contain the original version
$this->assertContains('Changed: Page1', $titles);
$this->assertNotContains('Changed: Page2', $titles);
@ -184,7 +184,7 @@ class VersionFeedFunctionalTest extends FunctionalTest
$titles = array_map(function ($item) {
return (string)$item->title;
}, $xml->xpath('//item') ?? []);
// TODO Unclear if this should contain the original version
$this->assertNotContains('Changed: Page1', $titles);
$this->assertContains('Changed: Page2', $titles);
}