Browse files

Merge pull request #68 from airdrummingfool/class_name_size

Migration file to change class name length, friendly warning in the console for too-long description
  • Loading branch information...
2 parents 35c5917 + 8a9cc5d commit 1d78ae8eb7d3eee93f60124f8d9fdecc12f3cf12 @burzum burzum committed Jun 4, 2012
Showing with 61 additions and 0 deletions.
  1. +58 −0 Config/Migration/003_increase_class_name_length.php
  2. +3 −0 Console/Command/MigrationShell.php
View
58 Config/Migration/003_increase_class_name_length.php
@@ -0,0 +1,58 @@
+<?php
+class IncreaseClassNameLength extends CakeMigration {
+
+/**
+ * Migration description
+ *
+ * @var string
+ * @access public
+ */
+ public $description = 'Increase the maximum length of class names.';
+
+/**
+ * Actions to be performed
+ *
+ * @var array $migration
+ * @access public
+ */
+ public $migration = array(
+ 'up' => array(
+ 'alter_field' => array(
+ 'schema_migrations' => array(
+ 'class' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 255, 'name' => 'class')
+ )
+ )
+ ),
+ 'down' => array(
+ 'alter_field' => array(
+ 'schema_migrations' => array(
+ 'class' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 33, 'name' => 'class')
+ )
+ )
+ )
+ );
+
+/**
+ * Before migration callback
+ *
+ * @param string $direction, up or down direction of migration process
+ * @return boolean Should process continue
+ * @access public
+ */
+ public function before($direction) {
+ return true;
+ }
+
+/**
+ * After migration callback
+ *
+ * @param string $direction, up or down direction of migration process
+ * @return boolean Should process continue
+ * @access public
+ */
+ public function after($direction) {
+ return true;
+ }
+}
+
+?>
View
3 Console/Command/MigrationShell.php
@@ -328,6 +328,9 @@ public function generate() {
if (!preg_match('/^([A-Za-z0-9_]+|\s)+$/', $name) || is_numeric($name[0])) {
$this->out('');
$this->err(__d('Migrations', 'Migration name (%s) is invalid. It must only contain alphanumeric characters and start with a letter.', $name));
+ } elseif (strlen($name) > 255) {
+ $this->out('');
+ $this->err(__d('Migrations', 'Migration name (%s) is invalid. It cannot be longer than 255 characters.', $name));
} else {
$name = str_replace(' ', '_', trim($name));
break;

0 comments on commit 1d78ae8

Please sign in to comment.