PHP code example of patricknelson / silverstripe-migrations
1. Go to this page and download the library: Download patricknelson/silverstripe-migrations library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
patricknelson / silverstripe-migrations example snippets
class Migration_ChangeSerializeToJson extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up() {
// Go through each DataObject and convert the column format from serialized to JSON.
foreach(MyDataObject::get() as $instance) {
$instance->EncodedField = json_encode(unserialize($instance->EncodedField));
}
}
/**
* Reverse the migration (this does the opposite of the method above).
*
* @return void
*/
public function down() {
// Go through each DataObject and convert the column format back from JSON to serialized again.
foreach(MyDataObject::get() as $instance) {
$instance->EncodedField = serialize(json_decode($instance->EncodedField));
}
}
}