Skip to content

Commit

Permalink
Merge branch '7' into 8
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed May 24, 2024
2 parents 80a09b0 + 9b8f546 commit 38079b7
Show file tree
Hide file tree
Showing 10 changed files with 2,706 additions and 2,235 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/dispatch-ci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
name: Dispatch CI

on:
# At 8:40 PM UTC, only on Saturday and Sunday
# At 12:00 AM UTC, only on Friday and Saturday
schedule:
- cron: '40 20 * * 6,0'
- cron: '0 0 * * 5,6'

permissions: {}

jobs:
dispatch-ci:
name: Dispatch CI
# Only run cron on the tractorcow-farm account
if: (github.event_name == 'schedule' && github.repository_owner == 'tractorcow-farm') || (github.event_name != 'schedule')
runs-on: ubuntu-latest
permissions:
contents: read
actions: write
steps:
- name: Dispatch CI
uses: silverstripe/gha-dispatch-ci@v1
8 changes: 6 additions & 2 deletions .github/workflows/keepalive.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
name: Keepalive

on:
# At 12:05 AM UTC, on day 20 of the month
# At 9:45 PM UTC, on day 6 of the month
schedule:
- cron: '5 0 20 * *'
- cron: '45 21 6 * *'
workflow_dispatch:

permissions: {}

jobs:
keepalive:
name: Keepalive
# Only run cron on the tractorcow-farm account
if: (github.event_name == 'schedule' && github.repository_owner == 'tractorcow-farm') || (github.event_name != 'schedule')
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- name: Keepalive
uses: silverstripe/gha-keepalive@v1
9 changes: 7 additions & 2 deletions .github/workflows/merge-up.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
name: Merge-up

on:
# At 12:05 AM UTC, only on Tuesday
# At 12:00 AM UTC, only on Tuesday
schedule:
- cron: '5 0 * * 2'
- cron: '0 0 * * 2'
workflow_dispatch:

permissions: {}

jobs:
merge-up:
name: Merge-up
# Only run cron on the tractorcow-farm account
if: (github.event_name == 'schedule' && github.repository_owner == 'tractorcow-farm') || (github.event_name != 'schedule')
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
steps:
- name: Merge-up
uses: silverstripe/gha-merge-up@v1
8 changes: 7 additions & 1 deletion .github/workflows/update-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ on:
workflow_dispatch:
# Run on a schedule of once per quarter
schedule:
- cron: '40 20 1 */3 *'
- cron: '20 4 1 */3 *'

permissions: {}

jobs:
update-js:
name: Update JS
# Only run cron on the tractorcow-farm account
if: (github.event_name == 'schedule' && github.repository_owner == 'tractorcow-farm') || (github.event_name != 'schedule')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
actions: write
steps:
- name: Update JS
uses: silverstripe/gha-update-js@v1
2 changes: 1 addition & 1 deletion client/dist/js/fluent.js

Large diffs are not rendered by default.

58 changes: 0 additions & 58 deletions src/Extension/FluentSiteTreeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\LiteralField;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\FieldType\DBHTMLText;
use TractorCow\Fluent\Extension\Traits\FluentAdminTrait;
use TractorCow\Fluent\Model\Locale;
Expand Down Expand Up @@ -528,60 +526,4 @@ public function actionComplete($form, $message)
{
return null;
}

/**
* Augment Localisation tab with clickable locale links to allow easy navigation between page localisations
*
* @param $summaryColumns
* @see FluentExtension::updateFluentCMSFields()
*/
protected function updateLocalisationTabColumns(&$summaryColumns)
{
parent::updateLocalisationTabColumns($summaryColumns);

if (!array_key_exists('Title', $summaryColumns)) {
return;
}

$controller = Controller::curr();

if (!$controller) {
return;
}

$request = $controller->getRequest();

if (!$request) {
return;
}

// This is to get URL only, getVars are not part of the URL
$url = $this->owner->CMSEditLink();

if (!$url) {
return;
}

// Pass getVars separately so we can process them later
$params = $request->getVars();
$url = Director::makeRelative($url);

$summaryColumns['Title'] = [
'title' => 'Title',
'callback' => function (Locale $object) use ($url, $params) {
if (!$object->RecordLocale()) {
return null;
}

$recordLocale = $object->RecordLocale();
$locale = $recordLocale->getLocale();
$params['l'] = $locale;
$localeLink = Controller::join_links($url, '?' . http_build_query($params));
$localeTitle = Convert::raw2xml($recordLocale->getTitle());
$render = sprintf('<a href="%s" target="_top">%s</a>', $localeLink, $localeTitle);

return DBField::create_field('HTMLVarchar', $render);
}
];
}
}
40 changes: 39 additions & 1 deletion src/Extension/Traits/FluentObjectTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace TractorCow\Fluent\Extension\Traits;

use SilverStripe\Admin\CMSEditLinkExtension;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig;
Expand All @@ -10,6 +14,7 @@
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataQuery;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\Queries\SQLSelect;
use TractorCow\Fluent\Model\Locale;
use TractorCow\Fluent\State\FluentState;
Expand Down Expand Up @@ -88,7 +93,7 @@ protected function augmentDataQueryCreation(
*/
protected function updateFluentCMSFields(FieldList $fields)
{
/** @var DataObject $owner */
/** @var DataObject|CMSEditLinkExtension $owner */
$owner = $this->owner;
if (!$owner->ID) {
return;
Expand All @@ -108,6 +113,39 @@ protected function updateFluentCMSFields(FieldList $fields)
'Locale' => 'Locale'
];

// Augment Localisation tab with clickable locale links to allow easy navigation between model localisations
if ($owner->hasExtension(CMSEditLinkExtension::class)) {
$controller = Controller::has_curr() ? Controller::curr() : null;
$request = $controller?->getRequest();

// Pass getVars separately so we can process them later
$params = $request?->getVars() ?? [];

// This is to get URL only, getVars are not part of the URL
$url = $owner->CMSEditLink();
$url = Director::makeRelative($url);

if ($url) {
$summaryColumns['Title'] = [
'title' => 'Title',
'callback' => function (Locale $object) use ($url, $params): ?DBField {
if (!$object->RecordLocale()) {
return null;
}

$recordLocale = $object->RecordLocale();
$locale = $recordLocale->getLocale();
$params['l'] = $locale;
$localeLink = Controller::join_links($url, '?' . http_build_query($params));
$localeTitle = Convert::raw2xml($recordLocale->getTitle());
$render = sprintf('<a href="%s" target="_top">%s</a>', $localeLink, $localeTitle);

return DBField::create_field('HTMLVarchar', $render);
}
];
}
}

// Let extensions override columns
$owner->extend('updateLocalisationTabColumns', $summaryColumns);
$columns->setDisplayFields($summaryColumns);
Expand Down
5 changes: 5 additions & 0 deletions src/Middleware/InitStateMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public function getIsFrontend(HTTPRequest $request)
*/
public function getIsDomainMode(HTTPRequest $request)
{
// Check environment for a ignored override
if (Environment::getEnv('SS_FLUENT_IGNORE_DOMAIN')) {
return false;
}

// Don't act in domain mode if none exist
if (!Domain::getCached()->exists()) {
return false;
Expand Down
11 changes: 11 additions & 0 deletions src/Model/CachableModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace TractorCow\Fluent\Model;

use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
Expand Down Expand Up @@ -68,6 +70,15 @@ public static function clearCached()
*/
protected static function databaseIsReady()
{
// Outside of dev/ don't actually do any checks, assume ready
if (Injector::inst()->has(HTTPRequest::class)) {
/** @var HTTPRequest $request */
$request = Injector::inst()->get(HTTPRequest::class);
if (stripos($request->getURL(false), 'dev/') !== 0) {
return true;
}
}

$object = DataObject::singleton(static::class);

// if any of the tables aren't created in the database
Expand Down
Loading

0 comments on commit 38079b7

Please sign in to comment.