Пример #1
0
 /**
  *
  * @return boolean 
  */
 public function fixPhones()
 {
     $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter();
     $dbAdapter->beginTransaction();
     try {
         $tables = array('PerData' => array('client_fone'));
         $now = App_Cache::load('current_fix_phone');
         if (empty($now)) {
             $now = 0;
         }
         $fixed = 0;
         $step = 2000;
         echo 'Step: ' . $step . ' - now: ' . $now . "\n\r";
         foreach ($tables as $table => $fields) {
             $db = App_Model_DbTable_Factory::get($table);
             $rows = $db->fetchAll(array(), array(), $step, $now);
             foreach ($rows as $row) {
                 $altered = false;
                 foreach ($fields as $field) {
                     $newPhone = App_General_String::cleanFone($row[$field]);
                     if (!empty($newPhone)) {
                         $row[$field] = $newPhone;
                         $altered = true;
                     }
                 }
                 if ($altered) {
                     $row->save();
                     $fixed++;
                 }
             }
         }
         $now += $step;
         App_Cache::save($now, 'current_fix_phone');
         $dbAdapter->commit();
         echo number_format($fixed, 0, '', '.') . ' Phones fixed' . "\n\r";
         echo str_repeat('-', 30) . "\n\r";
         return true;
     } catch (Exception $e) {
         $dbAdapter->rollBack();
         echo 'Error fixing phones: ' . $e->getMessage() . "\n\r";
         return false;
     }
 }