Skip to content

Instantly share code, notes, and snippets.

@boboldehampsink
Created September 4, 2015 08:40
Show Gist options
  • Save boboldehampsink/50961639ee909b4ae89c to your computer and use it in GitHub Desktop.
Save boboldehampsink/50961639ee909b4ae89c to your computer and use it in GitHub Desktop.
Migration
<?php
namespace Craft;
/**
* The class name is the UTC timestamp in the format of mYYMMDD_HHMMSS_pluginHandle_migrationName.
*/
class m150904_071603_inspections_DistanceText extends BaseMigration
{
/**
* Any migration code in here is wrapped inside of a transaction.
*
* @return bool
*/
public function safeUp()
{
// Get original field context
$context = craft()->content->fieldContext;
// Set supertable field context (there's only one supertable: 1)
craft()->content->fieldContext = 'superTableBlockType:1';
// Get distance field
$field = craft()->fields->getFieldByHandle('distance');
// Rename the field
$field->name = 'Meters';
// Save field
craft()->fields->saveField($field);
// Revert to original field context
craft()->content->fieldContext = $context;
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment