comanage-dev - Re: [comanage-dev] fix for extended attribute form and MySQL
Subject: COmanage Developers List
List archive
- From: Scott Koranda <>
- To: Benn Oshrin <>
- Cc:
- Subject: Re: [comanage-dev] fix for extended attribute form and MySQL
- Date: Wed, 28 Sep 2011 10:36:06 -0500
> Since we don't have data points beyond Postgres and MySQL, it's
> unclear whether the common case is it works (ie: Postgres) or it
> breaks (ie: MySQL), so it's not obvious which way the patch should
> work. That said, I'd be inclined to go with your "patch for MySQL"
> approach, since Postgres "just works".
>
Here is the diff:
Index: app/vendors/shells/database.php
===================================================================
--- app/vendors/shells/database.php (revision 99)
+++ app/vendors/shells/database.php (working copy)
@@ -50,7 +50,31 @@
// and (2) SERIAL isn't usable in an ALTER TABLE statement
// So we continue on error
$schema->ContinueOnError(true);
- $sql = $schema->ParseSchema($this->params['root'] .
'/app/config/schema/schema.xml');
+
+ // Parse the database XML schema from file unless we are targeting
MySQL
+ // in which case we use an XSL style sheet to first modify the schema
+ // so that boolean columns are cast to TINYINT(1) and the cakePHP
+ // automagic works. See
+ //
+ // https://bugs.internet2.edu/jira/browse/CO-175
+ //
+ if ($db->config['driver'] != 'mysql')
+ {
+ $sql = $schema->ParseSchema($this->params['root'] .
'/app/config/schema/schema.xml');
+ }
+ else
+ {
+ $xml = new DOMDocument;
+ $xml->load($this->params['root'] .
'/app/config/schema/schema.xml');
+
+ $xsl = new DOMDocument;
+ $xsl->load($this->params['root'] .
'/app/config/schema/boolean_mysql.xsl');
+
+ $proc = new XSLTProcessor;
+ $proc->importStyleSheet($xsl);
+
+ $sql = $schema->ParseSchemaString($proc->transformToXML($xml));
+ }
switch($schema->ExecuteSchema($sql))
{
@@ -71,4 +95,4 @@
}
}
}
-?>
\ No newline at end of file
+?>
Here is the XSL file I want to add to the repository:
$ cat app/config/schema/boolean_mysql.xsl
<!-- This XSL style sheet is used during database initialization
only if the database target server is MySQL. -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- match all <field type="L"> elements and add
the attribute 'size="1"' so that when used with
MySQL the boolean is cast to TINYINT(1) and
cakePHP automagic renders it to a checkbox -->
<xsl:template
match="field[@type='L']">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:attribute name="size">1</xsl:attribute>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
- [comanage-dev] fix for extended attribute form and MySQL, Scott Koranda, 09/27/2011
- Re: [comanage-dev] fix for extended attribute form and MySQL, Benn Oshrin, 09/27/2011
- Re: [comanage-dev] fix for extended attribute form and MySQL, Scott Koranda, 09/27/2011
- Re: [comanage-dev] fix for extended attribute form and MySQL, Scott Koranda, 09/27/2011
- Re: [comanage-dev] fix for extended attribute form and MySQL, Scott Koranda, 09/27/2011
- Re: [comanage-dev] fix for extended attribute form and MySQL, Scott Koranda, 09/27/2011
- Re: [comanage-dev] fix for extended attribute form and MySQL, Benn Oshrin, 09/28/2011
- Re: [comanage-dev] fix for extended attribute form and MySQL, Scott Koranda, 09/28/2011
- Re: [comanage-dev] fix for extended attribute form and MySQL, Scott Koranda, 09/28/2011
- Re: [comanage-dev] fix for extended attribute form and MySQL, Benn Oshrin, 09/28/2011
- Re: [comanage-dev] fix for extended attribute form and MySQL, Benn Oshrin, 09/28/2011
- Re: [comanage-dev] fix for extended attribute form and MySQL, Scott Koranda, 09/27/2011
- Re: [comanage-dev] fix for extended attribute form and MySQL, Scott Koranda, 09/27/2011
- Re: [comanage-dev] fix for extended attribute form and MySQL, Scott Koranda, 09/27/2011
- Re: [comanage-dev] fix for extended attribute form and MySQL, Scott Koranda, 09/27/2011
- Re: [comanage-dev] fix for extended attribute form and MySQL, Benn Oshrin, 09/27/2011
Archive powered by MHonArc 2.6.16.