Automatic crash reporting using FogBugz for PowerShell

Aug 3, 2015 in PowerShell

This morning I integrated our PowerShell processes into FogBugz by writing a small module that submits occurrences of all errors to BugzScout. You might want to do something similar so I did this write-up.

Broadly it works similar to BugzScoutLogWriter that I developed previously for integration with SilverStripe CMS. In this case however, we need to do the following things:

  1. Set the script to stop on all errors so they can be trapped instead of ending the execution of the script.
  2. Capture the error details and submit them to FogBugz
  3. Have an error occur. 😉

I’ve published the code in a Gist for you a have a look. I include the function in every script I use.

Jul 24, 2015 in Snippets

If your blog is more of a reference than a diary, why do you organise your posts in a timeline? Instead group them by category.

Jul 23, 2015 in Snippets

Let’s all turn off on-site commenting, and allow replies via moderated trackback. Anyone can start a blog and participate with increased civility and ownership. DONE.

Enum label lookup

Jul 23, 2015 in SilverStripe

In your datamodel you might have a Enum field such as this date-based dropdown:

public static $db = array(
    "Year"        => "Enum('2013, 2014, 2015')"

Internally, SilverStripe stores the index, so that when you retrieve the value in methods such as onBeforeWrite, instead of 2013 you will receive 1. Use the function below to retrieve the label of the Enum:

public function EnumLabel($field_name) {
    $enumValues = $this->dbObject($field_name)->enumValues();
    $label    = $enumValues[$this->$field_name];
    return $label;

// $year = $this->EnumLabel('Year');

LessThanOrEqual in SilverStripe 3.0

Jul 23, 2015 in SilverStripe

When adding a filter on a DataList sometimes you need to do a <= rather than a <. Unfortunately the LessThanOrEqual and GreatherThanOrEqual search filters do not exist in SilverStripe 3.0.x, they were added in 3.1.

Therefore we have to write our own where clause like the following example:

// Return all the sessions on or before the $date
$sessions = new DataList('AcademicSession');
$sessions = $sessions->where('"SessionStartDate" <= \'' . $date . '\'');

Jul 16, 2015 in Snippets

#iosstorymode “the best of the year of high quality of life and the other hand is the only thing that would have to go back.”

Jul 16, 2015 in Snippets

#iosstorymode Open a new note, enter the first word, then keep pressing the text suggestions button and see what stream of consciousness erupts.

Jul 15, 2015 in Snippets

Tip: keep a list of domains covered by security certificates and their expiry dates.

Jul 10, 2015 in Snippets

Tip: disable IFTT URL shorthening via account > preferences > URL Shorthening to post meaningful URLs to Twitter et al.

How to provide and manage your own permissions

Jul 7, 2015 in SilverStripe

At some point on your journey through the jungle that is SilverStripe, you will want to create permissions and assign users to them. You might have created a Page Category model admin to categorise your pages, and setup the relations between pages and their category. By default when you create a category as an admin they will not be visible to any content authors and any content authors that can access the model admin can’t create any new items.

The solution to this dilemma is to create a new permission (for example PROJECT_CategoryAdmin) and then let people with that permission mange the category items. This is how to go about it:

Create the permission

You will need to tell SilverStripe you are implementing permission by changing the class declaration as follows (changes in bold):

class Category extends DataObject implements PermissionProvider

To create the new permission you will have to write a providePermissions() method for the Category class:

      public function providePermissions() {
        return array(
            "PROJECT_CategoryAdmin" => array(
                'name' => 'Administer categories',
                'category' => 'PROJECT',
                'help' => 'Manage categories.'

Finally, implement the permission by declaring the canCreate, canDelete, canEdit and canView methods to your liking:

    public function canCreate($member = null) {
        return Permission::check('PROJECT_CategoryAdmin');

    public function canDelete($member = null) {
        return Permission::check('PROJECT_CategoryAdmin');

    public function canEdit($member = null) {
        return Permission::check('PROJECT_CategoryAdmin');

    public function canView($member = null) {
        return Permission::check('PROJECT_CategoryAdmin') ;

Don’t forget to create a Role and/or assign the permission to the right Group(s), to make sure the right users can manage your categories.