Skip to content

Instantly share code, notes, and snippets.

@kinglozzer
kinglozzer / isuckatsql.sql
Created June 16, 2022 11:49
Migrating elemental from a subclass of Page to Page
# Assumes the first non-zero ElementalAreaID in the versions table is the correct one to use
# (because they basically never change). Swap out table names as appropriate for your class.
# Don't forget to update Page_Live too!
UPDATE Page p
INNER JOIN
(
SELECT RecordID, ElementalAreaID
FROM CaseStudyPage_Versions
WHERE ElementalAreaID > 0
@kinglozzer
kinglozzer / Example.ss
Created March 24, 2021 14:20
Elemental + cacheinclude example
<% cache 'ElementFeatureBoxes', 'PerDataObjectCacheKeyCreator', 'CacheInclude', $ClassName, $ID %>
loop elements etc
<% end_cache %>
<?php
namespace App\Forms\GridField;
use Exception;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\ManyManyList;
use SilverStripe\ORM\ManyManyThroughList;
<?php
namespace App\ORM\FieldType;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\OptionsetField;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\FieldType\DBBoolean;
class DBNullableBoolean extends DBBoolean
@kinglozzer
kinglozzer / EmbedShortcodeProvider.php
Created September 6, 2019 09:43
Responsive CMS videos
<?php
namespace App\View\Shortcodes;
use SilverStripe\Core\Convert;
use SilverStripe\View\HTML;
use SilverStripe\View\Parsers\ShortcodeHandler;
use SilverStripe\View\Shortcodes\EmbedShortcodeProvider as SilverStripeEmbedShortcodeProvider;
/**
@kinglozzer
kinglozzer / BlogExtension.php
Created August 29, 2019 16:26
Category & uncategorised blog post filtering
<?php
/**
* Only show blog posts which are either:
*
* A) in the list of categories returned by getApplicableBlogCategories() or;
* B) do not have any categories assigned
*/
class BlogExtension extends Extension
{
@kinglozzer
kinglozzer / PaymentExtension.php
Last active January 22, 2021 15:02
Stripe + SilverStripe Omnipay
<?php
class PaymentExtension extends DataExtension
{
private static $db = [
'StripePaymentIntentReference' => 'Varchar(255)'
];
}
@kinglozzer
kinglozzer / patch.patch
Last active July 1, 2019 15:47
InterventionBackend logging
diff --git a/src/InterventionBackend.php b/src/InterventionBackend.php
index 81bcd97..dc251bc 100644
--- a/src/InterventionBackend.php
+++ b/src/InterventionBackend.php
@@ -13,6 +13,7 @@ use Intervention\Image\Size;
use InvalidArgumentException;
use LogicException;
use Psr\Http\Message\StreamInterface;
+use Psr\Log\LoggerInterface;
use Psr\SimpleCache\CacheInterface;
@kinglozzer
kinglozzer / LastVisitedMiddleware.php
Last active August 2, 2019 10:46
SilverStripe 4 - re-add member “LastVisited” date/time tracking
<?php
namespace App\Control\Middleware;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\Middleware\HTTPMiddleware;
use SilverStripe\ORM\DB;
use SilverStripe\Security\Security;
class LastVisitedMiddleware implements HTTPMiddleware
<?php
namespace App\Extensions;
class BaseElementExtension extends Extension
{
/**
* Flag to indiciate if this element is a new element. Used because isChanged('ID') seems to be unreliable
*
* @var bool