Development

Changeset 7371

You must first sign up to be able to contribute.

Changeset 7371

Show
Ignore:
Timestamp:
02/06/08 16:36:53 (10 months ago)
Author:
francois
Message:

sfPropelVersionableBehaviorPlugin Made the doc more explicit about multiple models (fixes #1820) and prepared 0.2.2 release

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelVersionableBehaviorPlugin/trunk/README

    r7368 r7371  
    1414   
    1515    {{{ 
    16       symfony plugin-install http://plugins.symfony-project.com/sfPropelVersionableBehaviorPlugin 
     16symfony plugin-install http://plugins.symfony-project.com/sfPropelVersionableBehaviorPlugin 
    1717    }}} 
    1818 
     
    2020 
    2121    {{{ 
    22       propel.builder.AddBehaviors = true 
    23     }}} 
    24    
    25   * Add necessary fields to your model
    26    
    27   {{{ 
    28   #!xml 
    29     <!-- schema.xml --> 
    30     <column name="uuid" type="CHAR" size="36" required="true" /> 
    31     <column name="version" type="INTEGER" size="11" required="true" /> 
    32     or 
    33     <!-- schema.yml --> 
    34     uuid:    { type: char, size: 36, required: true } 
    35     version: { type: integer, size: 11, required: true } 
    36   }}} 
     22propel.builder.AddBehaviors = true 
     23    }}} 
     24   
     25  * Add necessary fields to your each of your model tables that you want to make versionable
     26   
     27    {{{ 
     28#!xml 
     29<!-- schema.xml --> 
     30<column name="uuid" type="CHAR" size="36" required="true" /> 
     31<column name="version" type="INTEGER" size="11" required="true" /> 
     32or 
     33<!-- schema.yml --> 
     34uuid:    { type: char, size: 36, required: true } 
     35version: { type: integer, size: 11, required: true } 
     36    }}} 
    3737 
    3838  * Rebuild your database and model (the plugin uses two tables to store object version history) 
    3939   
    40   {{{ 
    41   #!sh 
    42     symfony propel-build-all 
    43   }}} 
    44    
    45   * Enable the behavior for one of your Propel model
    46  
    47     {{{ 
    48     #!php 
    49     <?php 
    50       // lib/model/Article.php 
    51       class Article 
    52      
    53      
    54  
    55       $columns_map = array('uuid'     => ArticlePeer::UUID 
    56                            'version'  => ArticlePeer::VERSION); 
    57   
    58       sfPropelBehavior::add('Article', array('versionable' => array('columns' => $columns_map))); 
    59     }}} 
    60  
    61    Column map values signification :  
     40    {{{ 
     41#!sh 
     42> php symfony propel-build-all 
     43    }}} 
     44   
     45  * Enable the behavior for the Propel models that you want to extend. For instance, to extend an `Article` Propel class
     46 
     47    {{{ 
     48#!php 
     49<?php 
     50// lib/model/Article.php 
     51class Article 
     52
     53
     54 
     55$columns_map = array('uuid'     => ArticlePeer::UUID, 
     56                     'version'  => ArticlePeer::VERSION); 
     57 
     58sfPropelBehavior::add('Article', array('versionable' => array('columns' => $columns_map))); 
     59   }}} 
     60 
     61   Column map values mean: 
    6262     * uuid : Model column holding resource's universally unique identifier (behavior takes care of generating these) 
    6363     * version : Model column holding resource's current version number 
     
    7171<?php 
    7272 
    73   $article = new Article(); 
    74   $article->setTitle('First version of article'); 
    75   $article->save(); // $article->getVersion() == 1 
    76  
    77   $article->setTitle('Second version of article'); 
    78   $article->save(); // $article->getVersion() == 2 
    79    
    80   $article->toVersion(1); // $article->getTitle() == 'First version of article' 
    81   $article->save(); // $article->getVersion() == 3 
    82  
     73$article = new Article(); 
     74$article->setTitle('First version of article'); 
     75$article->save(); // $article->getVersion() == 1 
     76 
     77$article->setTitle('Second version of article'); 
     78$article->save(); // $article->getVersion() == 2 
     79 
     80$article->toVersion(1); // $article->getTitle() == 'First version of article' 
     81$article->save(); // $article->getVersion() == 3 
    8382}}} 
    8483 
     
    8988<?php 
    9089 
    91   foreach ($article->getAllVersions() as $version) 
    92   { 
    93      $history_article = $version->getResourceInstance(); 
    94      echo sprintf("Version %d title : %s\n",  
    95                   $history_article->getVersion(),  
    96                   $history_article->getTitle()); 
    97   } 
    98  
    99   /*  
    100    * Outputs : 
    101    * 
    102    * Version 1 title : First version of article 
    103    * Version 2 title : Second version of article 
    104    * Version 3 title : First version of article 
    105    */ 
    106  
     90foreach ($article->getAllVersions() as $version) 
     91
     92   $history_article = $version->getResourceInstance(); 
     93   echo sprintf("Version %d title : %s\n",  
     94                $history_article->getVersion(),  
     95                $history_article->getTitle()); 
     96
     97 
     98/*  
     99 * Outputs: 
     100 * 
     101 * Version 1 title: First version of article 
     102 * Version 2 title: Second version of article 
     103 * Version 3 title: First version of article 
     104 */ 
    107105}}} 
    108106 
     
    120118<?php 
    121119 
    122   // lib/model/Article.php 
    123    
    124   public function versionConditionMet() 
    125   { 
    126     return $this->getTitle() != 'do not version me'; 
    127   } 
    128  
    129 }}} 
    130  
    131 {{{ 
    132 #!php 
    133 <?php 
    134  
    135   $article = new Article(); 
    136   $article->setTitle('New article'); 
    137   $article->save(); // article is saved and a new version is created 
    138  
    139   $article->setTitle('do not version me'); 
    140   $article->save(); // article is saved, no new version is created 
    141  
     120// lib/model/Article.php 
     121 
     122public function versionConditionMet() 
     123
     124  return $this->getTitle() != 'do not version me'; 
     125
     126}}} 
     127 
     128{{{ 
     129#!php 
     130<?php 
     131 
     132$article = new Article(); 
     133$article->setTitle('New article'); 
     134$article->save(); // article is saved and a new version is created 
     135 
     136$article->setTitle('do not version me'); 
     137$article->save(); // article is saved, no new version is created 
    142138}}} 
    143139 
     
    148144<?php 
    149145 
    150   sfPropelBehavior::add('Article', array('versionable' => array('columns' => $columns_map, 'conditional' => 'myMethod'))); 
     146sfPropelBehavior::add('Article', array('versionable' => array('columns' => $columns_map, 'conditional' => 'myMethod'))); 
    151147}}} 
    152148 
     
    157153<?php 
    158154 
    159   $previous_method = sfPropelVersionableBehavior::setVersionConditionMethod('myMethod'); 
     155$previous_method = sfPropelVersionableBehavior::setVersionConditionMethod('myMethod'); 
    160156}}} 
    161157 
     
    166162Enabling the behaviors adds / modifies the following method to the Propel objects : 
    167163 
    168  * `void save()` : Adds a new version to resource's version history 
    169  * `void delete()` : Deletes resource's version history 
    170  * `void toVersion(integer $version_number)` : Populates resource properties with values from the requested version 
    171  * `ResourceVersion getLastVersion()`  : Returns resource's last version 
    172  * `array getAllVersions()`  : Returns each resource version in an array 
     164 * `void save()`: Adds a new version to resource's version history 
     165 * `void delete()`: Deletes resource's version history 
     166 * `void toVersion(integer $version_number)`: Populates resource properties with values from the requested version 
     167 * `ResourceVersion getLastVersion()`: Returns resource's last version 
     168 * `array getAllVersions()`: Returns all resource versions in an array 
    173169  
    174170=== !ResourceVersion API === 
    175171 
    176  * `BaseObject getResourceInstance()` : returns resource instance populated with attributes from the version 
     172 * `BaseObject getResourceInstance()`: Returns resource instance populated with attributes from the version 
     173 * `int getNumber()`: Returns the version number of the version object 
     174 
    177175 
    178176=== sfPropelVersionableBehavior API === 
    179177 
    180  * (static) `string setVersionConditionMethod(string $method_name)` : Sets object method used to decide if a new version should be created 
    181  * (static) `string getVersionConditionMethod()` : Returns version condition method name 
     178 * (static) `string setVersionConditionMethod(string $method_name)`: Sets object method used to decide if a new version should be created 
     179 * (static) `string getVersionConditionMethod()`: Returns version condition method name 
    182180 
    183181== Roadmap == 
    184182 
    185 === 0.2.2 === 
    186  
    187  * add unit tests to check version_attributes deletion 
    188   
    189183=== 0.3 === 
    190184 
    191  * make plugin compatible with sfPropel's i18n capabilities 
    192  * depend on sfPropelUuidBehaviorPlugin for uuid management 
     185 * Add unit tests to check version_attributes deletion 
     186 * Make plugin compatible with sfPropel's i18n capabilities 
     187 * Replace uuid by a simple composite key class name + id 
    193188 
    194189== Changelog == 
     
    196191=== Trunk === 
    197192 
     193=== 2008-02-06 | 0.2.2 alpha === 
     194 
     195 * francois: Made the doc more explicit about multiple models (fixes #1820) 
    198196 * francois: Removed need for hardcoded foreign key (fixes #1562) 
    199197 * francois: Switched plugin schema to YAML 
    200198 * francois: Made the unit tests more adaptable 
    201199 
    202 === 2007-16-03 | 0.2.1 alpha === 
     200=== 2007-16-03 | 0.2.1 alpha === 
    203201 
    204202 * #1563 : does not create a version if YourClass::versionConditionMet() is not found (madman) 
  • plugins/sfPropelVersionableBehaviorPlugin/trunk/package.xml

    r7368 r7371  
    11<?xml version="1.0" encoding="UTF-8"?> 
    22<package xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" packagerversion="1.4.1" version="2.0" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> 
    3  <name>sfPropelVersionableBehaviorPlugin</name> 
    4  <channel>pear.symfony-project.com</channel> 
    5  <summary>Propel versionable behavior</summary> 
    6  <description>The `sfPropelVersionableBehaviorPlugin` is a symfony plugin that provides versioning capabilities to any Propel object.</description> 
    7  <lead> 
    8   <name>Tristan Rivoallan</name> 
    9   <user>trivoallan</user> 
    10   <email>tristan@rivoallan.net</email> 
    11   <active>yes</active> 
    12  </lead> 
    13  <date>2007-03-16</date> 
    14  <version> 
    15    <release>0.2.1</release> 
    16    <api>0.2.1</api> 
    17  </version> 
    18  <stability> 
    19   <release>alpha</release> 
    20   <api>alpha</api> 
    21  </stability> 
    22  <license uri="http://www.symfony-project.com/license">MIT license</license> 
    23  <notes>-</notes> 
    24  <contents> 
    25   <dir name="/">    
    26    <file name="README" role="data" /> 
    27    <file name="LICENSE" role="data" /> 
    28  
    29    <dir name="config"> 
    30      <file name="config.php" role="data" /> 
    31      <file name="schema.yml" role="data" /> 
    32    </dir> 
    33  
    34    <dir name="lib"> 
    35      <dir name="model"> 
    36        <file name="ResourceVersion.php" role="data" /> 
    37      </dir> 
    38    <file name="sfPropelVersionableBehavior.class.php" role="data" /> 
    39    <file name="sfPropelVersionableBehaviorToolkit.class.php" role="data" /> 
    40    </dir> 
    41  
    42   </dir> 
    43  </contents> 
    44  
    45  <dependencies> 
    46   <required> 
    47    <php> 
    48     <min>5.1.0</min> 
    49    </php> 
    50    <pearinstaller> 
    51     <min>1.4.1</min> 
    52    </pearinstaller> 
    53    <package> 
    54     <name>symfony</name> 
    55     <channel>pear.symfony-project.com</channel> 
    56     <min>1.0.0</min> 
    57    </package> 
    58   </required> 
    59  </dependencies> 
    60  
    61  <phprelease> 
    62  </phprelease> 
    63  
    64  <changelog> 
    65   <release> 
    66    <version> 
    67     <release>0.2.1</release> 
    68     <api>0.2.1</api> 
    69    </version> 
    70    <stability> 
     3  <name>sfPropelVersionableBehaviorPlugin</name> 
     4  <channel>pear.symfony-project.com</channel> 
     5  <summary>Propel versionable behavior</summary> 
     6  <description>The `sfPropelVersionableBehaviorPlugin` is a symfony plugin that provides versioning capabilities to any Propel object.</description> 
     7  <lead> 
     8    <name>Tristan Rivoallan</name> 
     9    <user>trivoallan</user> 
     10    <email>tristan@rivoallan.net</email> 
     11    <active>yes</active> 
     12  </lead> 
     13  <developer> 
     14    <name>Francois Zaninotto</name> 
     15    <user>fzaninotto</user> 
     16    <email>francois.zaninotto@symfony-project.com</email> 
     17    <active>yes</active> 
     18  </developer> 
     19  <date>2008-02-06</date> 
     20  <version> 
     21    <release>0.2.2</release> 
     22    <api>0.2.2</api> 
     23  </version> 
     24  <stability> 
    7125    <release>alpha</release> 
    7226    <api>alpha</api> 
    73    </stability> 
    74    <date>2007-02-17</date> 
    75    <license uri="http://www.symfony-project.com/license">MIT license</license> 
    76    <notes> 
     27  </stability> 
     28  <license uri="http://www.symfony-project.com/license">MIT license</license> 
     29  <notes>-</notes> 
     30  <contents> 
     31    <dir name="/"> 
     32      <file name="README" role="data"/> 
     33      <file name="LICENSE" role="data"/> 
     34      <dir name="config"> 
     35        <file name="config.php" role="data"/> 
     36        <file name="schema.yml" role="data"/> 
     37      </dir> 
     38      <dir name="lib"> 
     39        <dir name="model"> 
     40          <file name="ResourceVersion.php" role="data"/> 
     41        </dir> 
     42        <file name="sfPropelVersionableBehavior.class.php" role="data"/> 
     43        <file name="sfPropelVersionableBehaviorToolkit.class.php" role="data"/> 
     44      </dir> 
     45    </dir> 
     46  </contents> 
     47  <dependencies> 
     48    <required> 
     49      <php> 
     50        <min>5.1.0</min> 
     51      </php> 
     52      <pearinstaller> 
     53        <min>1.4.1</min> 
     54      </pearinstaller> 
     55      <package> 
     56        <name>symfony</name> 
     57        <channel>pear.symfony-project.com</channel> 
     58        <min>1.0.0</min> 
     59      </package> 
     60    </required> 
     61  </dependencies> 
     62  <phprelease> 
     63 </phprelease> 
     64  <changelog> 
     65    <release> 
     66      <version> 
     67        <release>0.2.2</release> 
     68        <api>0.2.2</api> 
     69      </version> 
     70      <stability> 
     71        <release>alpha</release> 
     72        <api>alpha</api> 
     73      </stability> 
     74      <date>2008-02-06</date> 
     75      <license uri="http://www.symfony-project.com/license">MIT license</license> 
     76      <notes> 
     77* francois: Removed need for hardcoded foreign key (fixes #1562) 
     78* francois: Switched plugin schema to YAML 
     79* francois: Made the unit tests more adaptable 
     80   </notes> 
     81    </release> 
     82    <release> 
     83      <version> 
     84        <release>0.2.1</release> 
     85        <api>0.2.1</api> 
     86      </version> 
     87      <stability> 
     88        <release>alpha</release> 
     89        <api>alpha</api> 
     90      </stability> 
     91      <date>2007-02-17</date> 
     92      <license uri="http://www.symfony-project.com/license">MIT license</license> 
     93      <notes> 
    7794 * #1563 : does not create a version if YourClass::versionConditionMet() is not found (madman) 
    7895 * #1564 : crashes while creating a new version if no prior version exists (madman) 
     
    8299 * updated unit tests and docs accordingly 
    83100   </notes> 
    84   </release> 
    85  
    86   <release> 
    87    <version> 
    88     <release>0.2.0</release> 
    89     <api>0.2.0</api> 
    90    </version> 
    91    <stability> 
    92     <release>alpha</release> 
    93     <api>alpha</api> 
    94    </stability> 
    95    <date>2007-02-17</date> 
    96    <license uri="http://www.symfony-project.com/license">MIT license</license> 
    97    <notes> 
     101    </release> 
     102    <release> 
     103      <version> 
     104        <release>0.2.0</release> 
     105        <api>0.2.0</api> 
     106      </version> 
     107      <stability> 
     108        <release>alpha</release> 
     109        <api>alpha</api> 
     110      </stability> 
     111      <date>2007-02-17</date> 
     112      <license uri="http://www.symfony-project.com/license">MIT license</license> 
     113      <notes> 
    98114 * made version number management more reliable 
    99115 * new `getLastVersion()` method 
     
    101117 * updated docs and unit tests accordingly 
    102118   </notes> 
    103   </release> 
    104  
    105   <release> 
    106    <version> 
    107     <release>0.1.0</release> 
    108     <api>0.1.0</api> 
    109    </version> 
    110    <stability> 
    111     <release>alpha</release> 
    112     <api>alpha</api> 
    113    </stability> 
    114    <date>2007-02-17</date> 
    115    <license uri="http://www.symfony-project.com/license">MIT license</license> 
    116    <notes> 
     119    </release> 
     120    <release> 
     121      <version> 
     122        <release>0.1.0</release> 
     123        <api>0.1.0</api> 
     124      </version> 
     125      <stability> 
     126        <release>alpha</release> 
     127        <api>alpha</api> 
     128      </stability> 
     129      <date>2007-02-17</date> 
     130      <license uri="http://www.symfony-project.com/license">MIT license</license> 
     131      <notes> 
    117132Initial public release 
    118133   </notes> 
    119   </release> 
    120  </changelog> 
     134    </release> 
     135  </changelog> 
    121136</package>