Skip to content

Instantly share code, notes, and snippets.

@khalwat
khalwat / m240430_143914_seed_db_data.php
Last active May 3, 2024 23:15
Craft CMS 5 content migration that creates & deletes Fields, EntryTypes & Sections, adds the Fields to the EntryTypes, adds the EntryTypes to the Sections, and then seeds the newly created Section with faked data. Also has a `safeDown()` method to revert what the migration adds
<?php
namespace craft\contentmigrations;
use Craft;
use craft\base\Element;
use craft\base\Field;
use craft\db\Migration;
use craft\elements\Entry;
use craft\errors\ElementNotFoundException;
@khalwat
khalwat / m231102_074933_add_index_to_demo_data.php
Last active December 6, 2023 12:17
Craft CMS content migration to add a database index to custom fields. Also has a `safeDown()` method to remove the indexes
<?php
namespace craft\contentmigrations;
use Craft;
use craft\db\Migration;
use craft\db\Table;
use craft\helpers\ElementHelper;
/**
@khalwat
khalwat / m231102_025445_seed_db_data.php
Last active December 6, 2023 12:17
Craft CMS content migration that creates & deletes Sections, Field Groups, and Fields, and adds them to the Section, and then seeds the newly created Section with faked data. Also has a `safeDown()` method to revert what the migration adds
<?php
namespace craft\contentmigrations;
use Craft;
use craft\base\Element;
use craft\base\Field;
use craft\db\Migration;
use craft\elements\Entry;
use craft\errors\ElementNotFoundException;
@khalwat
khalwat / Coverage Badges
Last active December 15, 2022 22:00
Coverage Badges
Coverage Badges
@khalwat
khalwat / load-balancer-app.php
Created February 26, 2018 17:25
Keep hashed directories consistent in a load balanced server environment with Craft CMS 3
<?php
/**
* Yii Application Config
*
* Edit this file at your own risk!
*
* The array returned by this file will get merged with
* vendor/craftcms/cms/src/config/app/main.php and [web|console].php, when
* Craft's bootstrap script is defining the configuration for the entire
* application.
@khalwat
khalwat / crontab_helper
Last active April 20, 2018 23:39
Never struggle with editing your crontab again; put this in the beginning of each of your crontabs
This is now part of craft-scripts:
https://github.com/nystudio107/craft-scripts
@khalwat
khalwat / BradsForMen.conf
Last active January 1, 2020 01:10
How to avoid .htaccess completely, and put your rewrite rules for Craft CMS in an Apache .conf file
# Using .htaccess is something you should avoid if at all possible, due to performance concerns:
# https://httpd.apache.org/docs/current/howto/htaccess.html
# Here's how to implement the rewrite rules for CraftCMS in an Apache .conf file; the key
# part is the "## Removes index.php from Craft URLs ##" section; the rest is provided
# just for context. Enjoy - andrew@nystudio107.com
<VirtualHost *:80>
ServerName BradsForMen.com
ServerAlias *.BradsForMen.com
DocumentRoot /var/www/BradsForMen/public
@khalwat
khalwat / set-project-perms.sh
Last active January 1, 2020 01:10
Properly set permissions for a Craft CMS install, including ensuring that files are all g-x. Set CHOWN_USER, CHOWN_GROUP, and BASE_DIR to whatever is appropriate, add directories that need to be writeable by the web server to DIRS[], then execute: sudo ./set-project-perms.sh PROJECT_NAME
This is now part of craft-scripts:
https://github.com/nystudio107/craft-scripts