From 831439120cc273305558a136dfbc37c3a1a336b3 Mon Sep 17 00:00:00 2001 From: Thomas Keller Date: Tue, 15 May 2012 22:38:27 +0200 Subject: [PATCH] Make the current_activity field in IDF_Project nullable and fix a problem in the migration 25's down method (issue 800) --- NEWS.mdtext | 18 ++++---- src/IDF/Migrations/25NullableProjectInTag.php | 1 + .../26NullableActivityInProject.php | 46 +++++++++++++++++++ src/IDF/Project.php | 2 + src/IDF/Tag.php | 1 + 5 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 src/IDF/Migrations/26NullableActivityInProject.php diff --git a/NEWS.mdtext b/NEWS.mdtext index 7205df9..9f62604 100644 --- a/NEWS.mdtext +++ b/NEWS.mdtext @@ -2,15 +2,17 @@ ## Bugfixes -- If an anonymous or authenticated user had no access - to any project in a forge, all projects were listed - for him (but still no one was actually accessible). - This has been fixed. +- If an anonymous or authenticated user had no access to any project in a + forge, all projects were listed for him (but still no one was actually + accessible). This has been fixed. -- Fixed a problem where the SyncGit plugin doesn't properly - updates the authorized_keys file when the public key - data contained slashes (thanks to Simon Gareste for the - fix!) +- Fixed a problem where the SyncGit plugin doesn't properly updates the + authorized_keys file when the public key data contained slashes (thanks + to Simon Gareste for the fix!) + +- Under PostgreSQL new projects could not be created due to a failing + foreign key relation. Adding project tags was not possible for a similar + reason. This has been fixed (issue 800, continued). # InDefero 1.3.2 - Wed May 09 20:05 2012 UTC diff --git a/src/IDF/Migrations/25NullableProjectInTag.php b/src/IDF/Migrations/25NullableProjectInTag.php index 22e10d7..0829acf 100644 --- a/src/IDF/Migrations/25NullableProjectInTag.php +++ b/src/IDF/Migrations/25NullableProjectInTag.php @@ -37,6 +37,7 @@ function IDF_Migrations_25NullableProjectInTag_up($params=null) function IDF_Migrations_25NullableProjectInTag_down($params=null) { + $engine = Pluf::f('db_engine'); $db = Pluf::db(); if ($engine === 'PostgreSQL') { $db->execute('ALTER TABLE '.$db->pfx.'idf_tags ALTER COLUMN project SET NOT NULL'); diff --git a/src/IDF/Migrations/26NullableActivityInProject.php b/src/IDF/Migrations/26NullableActivityInProject.php new file mode 100644 index 0000000..6335d84 --- /dev/null +++ b/src/IDF/Migrations/26NullableActivityInProject.php @@ -0,0 +1,46 @@ +execute('ALTER TABLE '.$db->pfx.'idf_projects ALTER COLUMN current_activity DROP NOT NULL'); + } else if ($engine === 'MySQL') { + $db->execute('ALTER TABLE '.$db->pfx.'idf_projects MODIFY current_activity MEDIUMINT NULL'); + // this is only needed for non-transactional setups where MySQL set 0 as default value + $db->execute('UPDATE '.$db->pfx.'idf_projects SET current_activity=NULL WHERE current_activity=0'); + } +} + +function IDF_Migrations_26NullableActivityInProject_down($params=null) +{ + $engine = Pluf::f('db_engine'); + $db = Pluf::db(); + if ($engine === 'PostgreSQL') { + $db->execute('ALTER TABLE '.$db->pfx.'idf_projects ALTER COLUMN current_activity SET NOT NULL'); + } else if ($engine === 'MySQL') { + $db->execute('ALTER TABLE '.$db->pfx.'idf_projects MODIFY current_activity MEDIUMINT NOT NULL'); + } +} diff --git a/src/IDF/Project.php b/src/IDF/Project.php index 04cd41b..b773281 100644 --- a/src/IDF/Project.php +++ b/src/IDF/Project.php @@ -105,6 +105,8 @@ class IDF_Project extends Pluf_Model 'type' => 'Pluf_DB_Field_Foreignkey', 'model' => 'IDF_ProjectActivity', 'blank' => true, + 'is_null' => true, + 'default' => null, 'verbose' => __('current project activity'), ), ); diff --git a/src/IDF/Tag.php b/src/IDF/Tag.php index 7b6349e..6809bc2 100644 --- a/src/IDF/Tag.php +++ b/src/IDF/Tag.php @@ -50,6 +50,7 @@ class IDF_Tag extends Pluf_Model 'model' => 'IDF_Project', 'blank' => true, 'is_null' => true, + 'default' => null, 'verbose' => __('project'), ), 'class' =>