示例#1
0
 /**
  * get file's edit info
  * add user name's full_pin and first_pinyin for user search use
  */
 function upgrade1()
 {
     $result = true;
     $info = 'Update test_user table successfully';
     $sql = 'ALTER TABLE `' . $this->newpre . 'test_user` ADD `full_pinyin` VARCHAR( 45 ) NULL AFTER `lock_version`';
     $result = mysql_query($sql);
     $sql = 'ALTER TABLE `' . $this->newpre . 'test_user` ADD `first_pinyin` VARCHAR( 45 ) NULL AFTER `full_pinyin`';
     $result = mysql_query($sql);
     $sql = 'UPDATE `' . $this->newpre . 'test_option` SET option_value = 17 WHERE option_name = "db_version"';
     $result = mysql_query($sql);
     $countSql = 'SELECT max(`id`) as count FROM `' . $this->newpre . 'test_user`';
     $countResult = mysql_query($countSql, $this->con);
     $countArr = mysql_fetch_array($countResult, MYSQL_ASSOC);
     $count = $countArr['count'];
     $start = -3;
     //special user,closed id -2, active id -1
     while ($start < $count) {
         $arr = array();
         for ($i = 0; $i < self::PAGE_SIZE; $i++) {
             $arr[] = $start++;
         }
         $sql = 'SELECT id,realname FROM ' . $this->newpre . 'test_user WHERE id IN(' . join(',', $arr) . ')';
         $userResult = mysql_query($sql, $this->con);
         while ($userResult && ($row = mysql_fetch_array($userResult, MYSQL_ASSOC))) {
             if (!empty($row['realname'])) {
                 $realname = $row['realname'];
                 $pinyin = PinyinService::pinyin(strtolower($realname));
                 $sql = 'UPDATE ' . $this->newpre . "test_user SET full_pinyin = '" . $pinyin[0] . "', first_pinyin = '" . $pinyin[1] . "' WHERE id = " . $row['id'];
                 $result = mysql_query($sql, $this->con);
                 if (!$result) {
                     $infos[] = $this->con ? mysql_error($this->con) : mysql_error();
                     $info = implode("\n", $infos);
                     return array(1, $info);
                 }
             }
         }
     }
     return array(0, $info);
 }
示例#2
0
 /**
  * get the update user pinyin sql
  * @return sql str
  */
 public function actionSyncPinyin()
 {
     set_time_limit(0);
     $count = TestUser::model()->count();
     echo 'total count:' . $count;
     $start = 0;
     $errorno = 0;
     while ($start < $count) {
         $condition = new CDbCriteria();
         $condition->limit = 100;
         $condition->offset = $start;
         $users = TestUser::model()->findAll($condition);
         foreach ($users as $user) {
             if (!empty($user['realname'])) {
                 $pinyin = PinyinService::pinyin(strtolower($user['realname']));
                 //not full translated
                 if ($pinyin[2] == false) {
                     $errorno += 1;
                     echo "Error#update {{test_user}} set full_pinyin='" . $pinyin[0] . "',first_pinyin='" . $pinyin[1] . "' where id=" . $user['id'] . " and realname = '" . $user['realname'] . "' and username='******'username'] . "' ;<br/>";
                 } else {
                     echo "update {{test_user}} set full_pinyin='" . $pinyin[0] . "',first_pinyin='" . $pinyin[1] . "' where id=" . $user['id'] . " ;<br/>";
                 }
             }
         }
         $start += 100;
     }
     echo "total error:" . $errorno . '<br/>';
 }
示例#3
0
 protected function afterValidate()
 {
     if (!$this->getErrors()) {
         if ($this->isNewRecord) {
             $this->password = md5($this->password);
             $pinyin = PinyinService::pinyin($this->realname);
             $this->full_pinyin = $pinyin[0];
             $this->first_pinyin = $pinyin[1];
         } else {
             $oldModel = TestUser::model()->findByPk($this->id);
             if ('' != $this->password && $this->password != $oldModel->password) {
                 $this->password = md5($this->password);
             } else {
                 $this->password = $oldModel->password;
             }
         }
     }
 }