Author: rande
Date: 2010-03-11 10:10:49 +0100 (Thu, 11 Mar 2010)
New Revision: 28472

Modified:
   
plugins/mgI18nPlugin/branches/sf1.2/lib/form/plugin/PluginmgI18nTargetsForm.class.php
   plugins/mgI18nPlugin/branches/sf1.2/lib/sfMessageSource_mgMySQL.class.php
   
plugins/mgI18nPlugin/branches/sf1.2/modules/mgI18nAdmin/lib/basemgI18nAdminActions.class.php
   plugins/mgI18nPlugin/branches/sf1.3/lib/mgI18N.class.php
   plugins/mgI18nPlugin/branches/sf1.3/lib/sfMessageSource_mgMySQL.class.php
   
plugins/mgI18nPlugin/branches/sf1.3/modules/mgI18nAdmin/lib/basemgI18nAdminActions.class.php
Log:
[mgI18nPlugin] add date management, fixes bugs

Modified: 
plugins/mgI18nPlugin/branches/sf1.2/lib/form/plugin/PluginmgI18nTargetsForm.class.php
===================================================================
--- 
plugins/mgI18nPlugin/branches/sf1.2/lib/form/plugin/PluginmgI18nTargetsForm.class.php
       2010-03-11 09:06:05 UTC (rev 28471)
+++ 
plugins/mgI18nPlugin/branches/sf1.2/lib/form/plugin/PluginmgI18nTargetsForm.class.php
       2010-03-11 09:10:49 UTC (rev 28472)
@@ -54,6 +54,7 @@
     $cultures = sfConfig::get('app_mgI18nPlugin_cultures_available');
     $source   = $this->getValue('source');
     $targets  = $this->getValue('targets');
+    $date     = strtotime('now');
   
     // build the catalogue array
     $markers = array();
@@ -75,7 +76,7 @@
     $stm->execute(array_merge($catalogues, array($source)));
     
     // initialize the update query statement
-    $update_stm = $pdo->prepare("UPDATE trans_unit SET target = ? WHERE msg_id 
= ?");
+    $update_stm = $pdo->prepare("UPDATE trans_unit SET target = ?, 
date_modified = ? WHERE msg_id = ?");
     
     // update translation
     foreach($stm->fetchAll(PDO::FETCH_ASSOC) as $trans_unit)
@@ -85,7 +86,7 @@
       
       $target = $targets[$culture];
       
-      $update_stm->execute(array($target, $trans_unit['msg_id']));
+      $update_stm->execute(array($target, $date, $trans_unit['msg_id']));
       
       unset($cultures[$culture]);
     }

Modified: 
plugins/mgI18nPlugin/branches/sf1.2/lib/sfMessageSource_mgMySQL.class.php
===================================================================
--- plugins/mgI18nPlugin/branches/sf1.2/lib/sfMessageSource_mgMySQL.class.php   
2010-03-11 09:06:05 UTC (rev 28471)
+++ plugins/mgI18nPlugin/branches/sf1.2/lib/sfMessageSource_mgMySQL.class.php   
2010-03-11 09:10:49 UTC (rev 28472)
@@ -322,11 +322,13 @@
       return $this->informations[$catalogue]['cat_id'];
     }
     
+    $date = strtotime('now');
+     
     $catalogues = array();
     if($force_create)
     {
-      $insert_catalogue_stm  = $this->pdo->prepare("INSERT INTO catalogue 
(name) VALUES (?)");
-      $insert_catalogue_stm->execute(array($catalogue));
+      $insert_catalogue_stm  = $this->pdo->prepare("INSERT INTO catalogue 
(name, date_created) VALUES (?, ?)");
+      $insert_catalogue_stm->execute(array($catalogue, $date));
       
       $select_catalogue_stm = $this->pdo->prepare("SELECT cat_id FROM 
catalogue WHERE name = ?");
       $select_catalogue_stm->execute(array($catalogue));
@@ -349,9 +351,12 @@
   function save($catalogue = 'messages')
   {
     $select_message_stm  = $this->pdo->prepare("SELECT * FROM trans_unit WHERE 
source = ? AND cat_id = ? LIMIT 1");
-    $insert_message_stm  = $this->pdo->prepare("INSERT INTO trans_unit 
(cat_id, source, target) VALUES (?, ?, ?)");
+    $insert_message_stm  = $this->pdo->prepare("INSERT INTO trans_unit 
(cat_id, source, target, date_modified) VALUES (?, ?, ?, ?)");
     
-    foreach($this->getRequestedMessages() as $catalogue => $messages)
+    $date       = strtotime('now');
+    $catalogues = $this->getRequestedMessages();
+    $in_prepare = array();
+    foreach($catalogues as $catalogue => $messages)
     {
   
       if(!is_array($messages) || count($messages) == 0)
@@ -359,10 +364,12 @@
         
         continue;
       }
-
+      
       $variant = $catalogue.'.'.$this->culture;
       $cat_id = $this->getCatalogueId($variant, true);
       
+      $in_prepare[$cat_id] = '?';
+      
       foreach($messages as $message)
       {
         $select_message_stm->execute(array($message['source'], $cat_id));
@@ -374,9 +381,16 @@
           continue;
         }
 
-        $insert_message_stm->execute(array($cat_id, $message['source'], 
$message['source']));
+        $insert_message_stm->execute(array($cat_id, $message['source'], 
$message['source'], $date));
       }
     }
+    
+    if(count($in_prepare) > 0)
+    {
+      $update_stm = $this->pdo->prepare(sprintf("UPDATE catalogue SET 
date_modified = ? WHERE cat_id IN(%s)", implode(',', $in_prepare)));
+      $update_stm->execute(array_merge(array($date), array_keys($in_prepare)));
+    }
+    
   }
 
   /**
@@ -415,9 +429,10 @@
   {
     
     $cat_id = $this->getCatalogueId($catalogue);
+    $date   = strtotime('now');
     
-    $stm = $this->pdo->prepare("UPDATE trans_unit SET target = ? WHERE cat_id 
= ? AND source = ?");
-    $stm->execute(array($target, $cat_id, $text));
+    $stm = $this->pdo->prepare("UPDATE trans_unit SET target = ?, 
date_modified = ? WHERE cat_id = ? AND source = ?");
+    $stm->execute(array($target, $date, $cat_id, $text));
   }
   
   /**
@@ -429,12 +444,11 @@
    */
   public function insert($source, $target, $comments, $catalogue = 'messages')
   {
-    
-    $stm = $this->pdo->prepare("INSERT INTO trans_unit (cat_id, source, 
target) VALUES (?, ?, ?)");
-    
+   
+    $stm    = $this->pdo->prepare("INSERT INTO trans_unit (cat_id, source, 
target, date_added) VALUES (?, ?, ?, ?)");    
     $cat_id = $this->getCatalogueId($catalogue, true);
     
-    return $stm->execute(array($cat_id, $source, $target));
+    return $stm->execute(array($cat_id, $source, $target, strtotime('now')));
   }
   
   public function getId()

Modified: 
plugins/mgI18nPlugin/branches/sf1.2/modules/mgI18nAdmin/lib/basemgI18nAdminActions.class.php
===================================================================
--- 
plugins/mgI18nPlugin/branches/sf1.2/modules/mgI18nAdmin/lib/basemgI18nAdminActions.class.php
        2010-03-11 09:06:05 UTC (rev 28471)
+++ 
plugins/mgI18nPlugin/branches/sf1.2/modules/mgI18nAdmin/lib/basemgI18nAdminActions.class.php
        2010-03-11 09:10:49 UTC (rev 28472)
@@ -90,14 +90,7 @@
       $form->save();
 
       // allow to tweak the clear_cache method
-      $event = $this->getContext()->getEventDispatcher()->notifyUntil(new 
sfEvent($params, 'mgI18n.clear_cache'));
-
-      if(!$event->isProcessed())
-      {
-        chdir(sfConfig::get('sf_root_dir'));
-        $cc = new sfCacheClearTask($this->getContext()->getEventDispatcher(), 
new sfFormatter);
-        $cc->run(array(), array('--type=i18n'));
-      }
+      $this->getContext()->getEventDispatcher()->notifyUntil(new 
sfEvent($params, 'mgI18n.clear_cache'));
     }
     
     return sfView::NONE;

Modified: plugins/mgI18nPlugin/branches/sf1.3/lib/mgI18N.class.php
===================================================================
--- plugins/mgI18nPlugin/branches/sf1.3/lib/mgI18N.class.php    2010-03-11 
09:06:05 UTC (rev 28471)
+++ plugins/mgI18nPlugin/branches/sf1.3/lib/mgI18N.class.php    2010-03-11 
09:10:49 UTC (rev 28472)
@@ -32,7 +32,7 @@
   {
     if($this->options['learning_mode'])
     {
-      // save only on debug mode
+      // save only on learning mode
       if(!$this->getMessageSource() instanceof sfMessageSource_mgMySQL)
       {
         throw new sfException('The message source must be an instance of 
sfMessageSource_mgMySQL');
@@ -112,6 +112,13 @@
     return $this->getMessageSource()->getRequestedMessages();
   }
 
+  /**
+   * return the language used in a given catalogue name
+   *
+   * @static
+   * @param  string $catalogue the catalogue name
+   * @return string language
+   */
   public static function getLanguage($catalogue)
   {
 

Modified: 
plugins/mgI18nPlugin/branches/sf1.3/lib/sfMessageSource_mgMySQL.class.php
===================================================================
--- plugins/mgI18nPlugin/branches/sf1.3/lib/sfMessageSource_mgMySQL.class.php   
2010-03-11 09:06:05 UTC (rev 28471)
+++ plugins/mgI18nPlugin/branches/sf1.3/lib/sfMessageSource_mgMySQL.class.php   
2010-03-11 09:10:49 UTC (rev 28472)
@@ -1,7 +1,7 @@
 <?php
 /*
  * This file is part of the mgWidgetsPlugin package.
- * (c) 2008 MenuGourmet
+ * (c) 2008 MenuGourmet 
  *
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
@@ -15,7 +15,7 @@
  */
 class sfMessageSource_mgMySQL extends sfMessageSource
 {
-  protected
+  protected 
     $informations  = null,
     $application   = null, // the application name used
     $pdo           = null  // the PDO connection
@@ -31,16 +31,16 @@
   {
     $this->source = (string) $source;
     $this->pdo    = $this->connect();
-
+    
     $this->loadInformations();
   }
 
   public function getConnection()
   {
-
+    
     return $this->pdo;
   }
-
+  
   /**
    * This code is very bad ... don't do that at home
    *
@@ -48,11 +48,11 @@
   public function connect()
   {
     static $connection;
-
+    
     // try to get the PDO connection object from the sfContext
     if(sfContext::hasInstance())
     {
-
+      
       return sfContext::getInstance()->getDatabaseConnection($this->source);
     }
 
@@ -67,8 +67,8 @@
 
     return $connection;
   }
-
-
+  
+  
   public function load($catalogue = null)
   {
     if($catalogue == null || strlen($catalogue) == 0)
@@ -97,7 +97,7 @@
       $this->informations[$row[1]] = array('cat_id' => $row[0], 
'date_modified' => $row[2]);
     }
   }
-
+  
   /**
    * Gets all the variants of a particular catalogue.
    *
@@ -131,10 +131,10 @@
     {
       $this->untranslated[$catalogue] = array();
     }
-
+    
     $this->untranslated[$catalogue][md5($message_information['source'])] = 
$message_information;
   }
-
+  
   /**
    * Adds a untranslated message to the source. Need to call save()
    * to save the messages to source.
@@ -143,22 +143,22 @@
    */
   public function append($message)
   {
-
+    
   }
-
+  
   public function getRequestedMessages()
   {
 
     return $this->untranslated;
   }
-
+  
   /**
    * @see sfMessageSource_MySQL
    *
    */
   protected function getLastModified($source)
   {
-
+     
     if(array_key_exists($source, $this->informations))
     {
 
@@ -178,7 +178,7 @@
     return array_key_exists($variant, $this->informations);
   }
 
-
+  
   /**
    * @see sfMessageSource_MySQL
    *
@@ -200,12 +200,12 @@
     $cat_id = $this->informations[$variant]['cat_id'];
 
     // first get the catalogue ID
-
+    
     $stm = $this->pdo->prepare("SELECT COUNT(*) FROM trans_unit WHERE cat_id = 
?");
     $stm->execute(array($cat_id));
-
+    
     $val = $stm->fetchAll(PDO::FETCH_NUM);
-
+    
     $count = 0;
     if(count($val) > 0)
     {
@@ -225,7 +225,7 @@
 
     $stm = $this->pdo->prepare("UPDATE catalogue SET date_modified = ? WHERE 
cat_id = ?");
     $stm->execute(array($time, $cat_id));
-
+    
     if(array_key_exists($variant, $this->informations))
     {
 
@@ -239,7 +239,7 @@
 
     return $result;
   }
-
+  
   /**
    * Gets an array of messages for a particular catalogue and cultural variant.
    *
@@ -258,7 +258,7 @@
     );
 
     $stm->execute(array($variant));
-
+    
     $result = array();
 
     foreach($stm->fetchAll(PDO::FETCH_NUM) as $row)
@@ -271,31 +271,31 @@
 
     return $result;
   }
-
+  
   public function getApplicationName()
   {
-
+    
     return sfConfig::get('mg_i18n_global_application', 
sfProjectConfiguration::getActive()->getApplication());
   }
-
+  
   /**
    * Returns a list of catalogue as key and all it variants as value.
    *
-   * @return array list of catalogues
+   * @return array list of catalogues 
    */
   function catalogues()
   {
 
     $stm = $this->pdo->prepare('SELECT name FROM catalogue ORDER BY name');
     $stm->execute();
-
+    
     $result = array();
-
+    
     foreach($stm->fetchAll(PDO::FETCH_NUM) as $row)
     {
       $details = explode('.', $row[0]);
       array_shift($details);
-
+      
       if (!isset($details[1]))
       {
         $details[1] = null;
@@ -306,7 +306,7 @@
 
     return $result;
   }
-
+  
   /**
    * return the catalogue id
    *
@@ -315,31 +315,33 @@
    */
   public function getCatalogueId($catalogue, $force_create = false)
   {
-
+    
     if(isset($this->informations[$catalogue]))
     {
-
+      
       return $this->informations[$catalogue]['cat_id'];
     }
-
+    
+    $date = strtotime('now');
+     
     $catalogues = array();
     if($force_create)
     {
-      $insert_catalogue_stm  = $this->pdo->prepare("INSERT INTO catalogue 
(name) VALUES (?)");
-      $insert_catalogue_stm->execute(array($catalogue));
-
+      $insert_catalogue_stm  = $this->pdo->prepare("INSERT INTO catalogue 
(name, date_created) VALUES (?, ?)");
+      $insert_catalogue_stm->execute(array($catalogue, $date));
+      
       $select_catalogue_stm = $this->pdo->prepare("SELECT cat_id FROM 
catalogue WHERE name = ?");
       $select_catalogue_stm->execute(array($catalogue));
       $catalogues = $select_catalogue_stm->fetchAll(PDO::FETCH_ASSOC);
     }
-
+    
     $cat_id = count($catalogues) > 0 ? $catalogues[0]['cat_id'] : false;
-
+    
     return $this->informations[$catalogue]['cat_id'] = $cat_id;
   }
 
   /**
-   * Saves the list of untranslated blocks to the translation source.
+   * Saves the list of untranslated blocks to the translation source. 
    * If the translation was not found, you should add those
    * strings to the translation source via the <b>append()</b> method.
    *
@@ -349,20 +351,25 @@
   function save($catalogue = 'messages')
   {
     $select_message_stm  = $this->pdo->prepare("SELECT * FROM trans_unit WHERE 
source = ? AND cat_id = ? LIMIT 1");
-    $insert_message_stm  = $this->pdo->prepare("INSERT INTO trans_unit 
(cat_id, source, target) VALUES (?, ?, ?)");
-
-    foreach($this->getRequestedMessages() as $catalogue => $messages)
+    $insert_message_stm  = $this->pdo->prepare("INSERT INTO trans_unit 
(cat_id, source, target, date_modified) VALUES (?, ?, ?, ?)");
+    
+    $date       = strtotime('now');
+    $catalogues = $this->getRequestedMessages();
+    $in_prepare = array();
+    foreach($catalogues as $catalogue => $messages)
     {
-
+  
       if(!is_array($messages) || count($messages) == 0)
       {
-
+        
         continue;
       }
-
+      
       $variant = $catalogue.'.'.$this->culture;
       $cat_id = $this->getCatalogueId($variant, true);
-
+      
+      $in_prepare[$cat_id] = '?';
+      
       foreach($messages as $message)
       {
         $select_message_stm->execute(array($message['source'], $cat_id));
@@ -370,13 +377,20 @@
 
         if(count($trans_unit) == 1)
         {
-
+          
           continue;
         }
 
-        $insert_message_stm->execute(array($cat_id, $message['source'], 
$message['source']));
+        $insert_message_stm->execute(array($cat_id, $message['source'], 
$message['source'], $date));
       }
     }
+    
+    if(count($in_prepare) > 0)
+    {
+      $update_stm = $this->pdo->prepare(sprintf("UPDATE catalogue SET 
date_modified = ? WHERE cat_id IN(%s)", implode(',', $in_prepare)));
+      $update_stm->execute(array_merge(array($date), array_keys($in_prepare)));
+    }
+    
   }
 
   /**
@@ -384,7 +398,7 @@
    *
    * @param string $message   the source message to delete.
    * @param string $catalogue the catalogue to delete from.
-   * @return boolean true if deleted, false otherwise.
+   * @return boolean true if deleted, false otherwise. 
    */
   function delete($message, $catalogue = 'messages')
   {
@@ -393,10 +407,10 @@
     // the catalogue does not exist
     if($cat_id === false)
     {
-
+      
       return false;
     }
-
+    
     $stm = $this->pdo->prepare("DELETE FROM trans_unit WHERE cat_id = ? AND 
source = ?");
 
     return $stm->execute(array($cat_id, $message));
@@ -409,17 +423,18 @@
    * @param string $target    the new translation string.
    * @param string $comments  comments
    * @param string $catalogue the catalogue of the translation.
-   * @return boolean true if translation was updated, false otherwise.
+   * @return boolean true if translation was updated, false otherwise. 
    */
   function update($text, $target, $comments, $catalogue = 'messages')
   {
-
+    
     $cat_id = $this->getCatalogueId($catalogue);
-
-    $stm = $this->pdo->prepare("UPDATE trans_unit SET target = ? WHERE cat_id 
= ? AND source = ?");
-    $stm->execute(array($target, $cat_id, $text));
+    $date   = strtotime('now');
+    
+    $stm = $this->pdo->prepare("UPDATE trans_unit SET target = ?, 
date_modified = ? WHERE cat_id = ? AND source = ?");
+    $stm->execute(array($target, $date, $cat_id, $text));
   }
-
+  
   /**
    * Store a message into the database
    *
@@ -429,14 +444,13 @@
    */
   public function insert($source, $target, $comments, $catalogue = 'messages')
   {
-
-    $stm = $this->pdo->prepare("INSERT INTO trans_unit (cat_id, source, 
target) VALUES (?, ?, ?)");
-
+   
+    $stm    = $this->pdo->prepare("INSERT INTO trans_unit (cat_id, source, 
target, date_added) VALUES (?, ?, ?, ?)");    
     $cat_id = $this->getCatalogueId($catalogue, true);
-
-    return $stm->execute(array($cat_id, $source, $target));
+    
+    return $stm->execute(array($cat_id, $source, $target, strtotime('now')));
   }
-
+  
   public function getId()
   {
     return md5($this->source);

Modified: 
plugins/mgI18nPlugin/branches/sf1.3/modules/mgI18nAdmin/lib/basemgI18nAdminActions.class.php
===================================================================
--- 
plugins/mgI18nPlugin/branches/sf1.3/modules/mgI18nAdmin/lib/basemgI18nAdminActions.class.php
        2010-03-11 09:06:05 UTC (rev 28471)
+++ 
plugins/mgI18nPlugin/branches/sf1.3/modules/mgI18nAdmin/lib/basemgI18nAdminActions.class.php
        2010-03-11 09:10:49 UTC (rev 28472)
@@ -90,14 +90,7 @@
       $form->save();
 
       // allow to tweak the clear_cache method
-      $event = $this->getContext()->getEventDispatcher()->notifyUntil(new 
sfEvent($params, 'mgI18n.clear_cache'));
-
-      if(!$event->isProcessed())
-      {
-        chdir(sfConfig::get('sf_root_dir'));
-        $cc = new sfCacheClearTask($this->getContext()->getEventDispatcher(), 
new sfFormatter);
-        $cc->run(array(), array('--type=i18n'));
-      }
+      $this->getContext()->getEventDispatcher()->notifyUntil(new 
sfEvent($params, 'mgI18n.clear_cache'));
     }
     
     return sfView::NONE;

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to