Skip to content

Instantly share code, notes, and snippets.

View wilr's full-sized avatar

Will Rossiter wilr

View GitHub Profile
@wilr
wilr / Page.php
Created February 6, 2018 20:35
Snippet for namespaced SilverStripe Pagetypes to find their controller in a different namespace.
<?php
namespace App\Project\Model;
use SilverStripe\Core\ClassInfo;
use SilverStripe\CMS\Model\SiteTree;
use App\Project\Control\PageController;
class Page extends SiteTree
{
SET @old='https://www.production.com';
SET @new='http://local.dev';
UPDATE wp_options SET option_value = replace(option_value, @old, @new) WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, @old, @new);
UPDATE wp_posts SET post_content = replace(post_content, @old, @new);
UPDATE wp_postmeta SET meta_value = replace(meta_value,@old,@new);
<?php
class SearchIndexWithTags extends SolrSearchIndex
{
public function init()
{
$this->addFilterField('SiteTree_TagID');
declare @qry nvarchar(max);
select @qry = (
select 'IF EXISTS(SELECT * FROM sys.indexes WHERE name='''+ i.name +''' AND object_id = OBJECT_ID(''['+s.name+'].['+o.name+']'')) drop index ['+i.name+'] ON ['+s.name+'].['+o.name+']; '
from sys.indexes i
inner join sys.objects o on i.object_id=o.object_id
inner join sys.schemas s on o.schema_id = s.schema_id
where o.type<>'S' and is_primary_key<>1 and index_id>0
and s.name!='sys' and s.name!='sys' and is_unique_constraint=0
for xml path(''));
@wilr
wilr / parameter_fix.diff
Created April 10, 2016 22:57
Better MySQL showqueries debugging in SilverStripe 3.2+
diff --git a/model/connect/Database.php b/model/connect/Database.php
index cfdd628..53b236f 100644
--- a/model/connect/Database.php
+++ b/model/connect/Database.php
@@ -132,7 +132,8 @@ abstract class SS_Database {
$sql,
function($sql) use($connector, $parameters, $errorLevel) {
return $connector->preparedQuery($sql, $parameters, $errorLevel);
- }
+ },
@wilr
wilr / Member.php
Last active August 29, 2015 14:17
Member optimisation.
diff --git a/security/Member.php b/security/Member.php
index 6fe8278..05f5d14 100644
--- a/security/Member.php
+++ b/security/Member.php
@@ -163,6 +163,9 @@ class Member extends DataObject implements TemplateGlobalProvider {
*/
private static $session_regenerate_id = true;
+ private static $_cached_current_member_id;
+ private static $_cached_current_member;
@wilr
wilr / GoogleSitemapController_sitemap.ss
Created November 8, 2014 19:37
Implement localisation for Google Sitemaps
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='{$BaseHref}googlesitemaps/templates/xml-sitemap.xsl'?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<% loop $Items %>
<url>
<loc>$AbsoluteLink</loc><% if Localisations %><% loop Localisations %>
<xhtml:link rel="alternate" hreflang="$PlaceHolderForLocale" href="$AbsoluteLink" /><% end_loop %><% end_if %>
<% if $LastEdited %><lastmod>$LastEdited.Format(c)</lastmod><% end_if %>
<% if $ChangeFrequency %><changefreq>$ChangeFrequency</changefreq><% end_if %>
<% if $GooglePriority %><priority>$GooglePriority</priority><% end_if %>
diff --git a/code/model/UserDefinedForm.php b/code/model/UserDefinedForm.php
index 9f96dd7..58e91d6 100755
--- a/code/model/UserDefinedForm.php
+++ b/code/model/UserDefinedForm.php
@@ -1055,6 +1055,8 @@ JS
}
}
+ Session::set('LastSubmissionFor'. $this->ID, serialize($submittedForm));
+
@wilr
wilr / gist:b688b612af3f6f08b1bd
Created June 29, 2014 10:54
Output contents of SilverStripe template mainfest in a readable
php -r "echo '<pre>'; print_r(unserialize(file_get_contents('silverstripe-cache/apache/templatemanifest/cache_manifest')));"
@wilr
wilr / generate_animated_photos.sh
Last active August 29, 2015 14:03
Generate an animated sequence of photos. I used iPhoto export to generate a Images folder of images at a set size and resolution.
#!/bin/bash
# normalize filenames exported from iPhoto to XXXX.jpg so that the frames come
# out in order
cd Images
for f in *.jpg; do
num=`basename $f .jpg | cut -d '.' -f 1`
name=`printf "%0.4i.jpg\n" $num`
[ ! -f $name ] && mv $f $name
done