ここの情報は古いです。ご理解頂いた上でお取り扱いください。

Changeset 12849


Ignore:
Timestamp:
Sep 7, 2009, 7:01:08 PM (13 years ago)
Author:
fukamachi
Message:

db converter - added a convert method for Ashiato. and fixed some bugs. this is the first executable program

File:
1 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/branches/fukamachi/db-convert-from-2.x/lib/task/openpneUpgradeFrom2Task.class.php

    r12840 r12849  
    1111class openpneUpgradeFrom2Task extends sfDoctrineBaseTask
    1212{
    13   private $dsn3                 = '';
    14   private $dsn2                 = '';
    15   private $username             = '';
    16   private $password             = '';
    17   private $encryptKey           = '';
    18   private $date                 = '0000-00-00 00:00:00';
    19   private $mapCategoryIds       = array();
    20   private $mapFileNameToId      = array();
    21   private $birthdayProfileId    = null;
    22   private $validatorFile        = null;
    23   private $unreadDiaryIds       = array();
    24   private $memberIds            = array();
    25 
    26   private $memoryBuf            = 0;
     13  private $dsn3                = '';
     14  private $dsn2                = '';
     15  private $username            = '';
     16  private $password            = '';
     17  private $encryptKey          = '';
     18  private $date                = '0000-00-00 00:00:00';
     19  private $mapCategoryIds      = array();
     20  private $mapFileNameToId     = array();
     21  private $mapCommunityAdminId = array();
     22  private $birthdayProfileId   = null;
     23  private $validatorFile       = null;
     24  private $unreadDiaryIds      = array();
     25  private $memberIds           = array();
     26  private $communityIds        = array();
     27
     28  private $memoryBuf           = 0;
    2729
    2830  protected function configure()
     
    4850    $pluginInstall->run(array('opCommunityTopicPlugin'), array('--stability=beta'));
    4951    //$pluginInstall->run(array('opMessagePlugin'), array('--stability=beta'));
    50     //$pluginInstall->run(array('opAshiatoPlugin'), array('--stability=beta'));
     52    $pluginInstall->run(array('opAshiatoPlugin'), array('--stability=beta'));
    5153
    5254    // install OpenPNE3
     
    99101
    100102    // clear db records
    101     $tables = array('Blacklist', 'File', 'FileBin', 'CommunityCategory', 'Community', 'CommunityConfig', 'CommunityMember', 'Member', 'MemberConfig', 'MemberImage', 'Profile', 'ProfileTranslation', 'ProfileOption', 'ProfileOptionTranslation', 'MemberProfile', 'MemberRelationship', 'CommunityTopic', 'CommunityEvent', 'Diary', 'DiaryImage', 'DiaryComment', 'DiaryCommentImage', 'DiaryCommentUnread', /*'Message', 'MessageSendList', 'DeletedMessage', 'MessageFile'*/);
     103    $tables = array('Blacklist', 'File', 'FileBin', 'CommunityCategory', 'Community', 'CommunityConfig', 'CommunityMember', 'Member', 'MemberConfig', 'MemberImage', 'Profile', 'ProfileTranslation', 'ProfileOption', 'ProfileOptionTranslation', 'MemberProfile', 'MemberRelationship', 'CommunityTopic', 'CommunityEvent', 'Diary', 'DiaryImage', 'DiaryComment', 'DiaryCommentImage', 'DiaryCommentUnread', /*'Message', 'MessageSendList', 'DeletedMessage', 'MessageFile', */'Ashiato');
    102104
    103105    foreach ($tables as $table)
     
    129131    print "converting ProfileOption : ".memory_get_usage()."\n";
    130132    $this->convertProfileOption();
    131     //print "converting MemberProfile : ".memory_get_usage()."\n";
    132     //$this->convertMemberProfile();
     133    print "converting MemberProfile : ".memory_get_usage()."\n";
     134    $this->convertMemberProfile();
    133135    print "converting MemberRelationship : ".memory_get_usage()."\n";
    134136    $this->convertMemberRelationship();
    135     print "converting CommunityTopicAndComment : ".memory_get_usage()."\n";
     137    print "converting CommunityTopic and CommunityTopicComment : ".memory_get_usage()."\n";
    136138    $this->convertCommunityTopicAndComment();
    137     print "converting CommunityEventAndComment : ".memory_get_usage()."\n";
     139    print "converting CommunityEvent and CommunityEventComment : ".memory_get_usage()."\n";
    138140    $this->convertCommunityEventAndComment();
    139     print "converting DiaryAndImage : ".memory_get_usage()."\n";
     141    print "converting Diary and DiaryImage : ".memory_get_usage()."\n";
    140142    $this->convertDiaryAndImage();
    141     print "converting DiaryCommentAndImage : ".memory_get_usage()."\n";
     143    print "converting DiaryComment and DiaryCommentImage : ".memory_get_usage()."\n";
    142144    $this->convertDiaryCommentAndImage();
    143     //print "converting MessageTables : ".memory_get_usage()."\n";
     145    //print "converting Message tables : ".memory_get_usage()."\n";
    144146    //$this->convertMessageTables();
     147    print "converting Ashiato : ".memory_get_usage()."\n";
     148    $this->convertAshiato();
    145149
    146150    // delete models' cache
     
    366370        $this->createConfigs('CommunityConfig', $param, $configs);
    367371
     372        $this->mapCommunityAdminId[$cCommu->getCCommuId()] = $cCommu->getCMemberIdAdmin();
     373        $this->communityIds[] = $cCommu->getCCommuId();
    368374        $cCommu->free();
    369375      }
     
    382388      {
    383389        // NOTICE: ignore if the community this member joins is not exist
    384         if (!$this->isExist('Community', $cCommuMember->getCCommuId()))
     390        if (!$this->isExistCommunity($cCommuMember->getCCommuId()))
    385391        {
    386392          $cCommuMember->free();
     
    396402            );
    397403        $this->connectTo2();
    398         if (
    399             $this->isExist('CCommu', array(
    400                 'c_commu_id'        => $cCommuMember->getCCommuId(),
    401                 'c_member_id_admin' => $cCommuMember->getCCommuMemberId()
    402                 ))
    403            )
     404        if ($cCommuMember->getCMemberId() === $this->mapCommunityAdminId[$cCommuMember->getCCommuId()])
    404405        {
    405406          $param['position'] = 'admin';
     
    424425      {
    425426        $param = array(
    426             'id'         => $cMember->getCMemberId(),
    427             'name'       => $cMember->getNickname(),
    428             'created_at' => $cMember->getRDate(),
    429             'updated_at' => $cMember->getUDatetime(),
    430             'is_active'  => !$cMember->getIsLoginRejected(),
     427            'id'               => $cMember->getCMemberId(),
     428            'name'             => $cMember->getNickname(),
     429            'invite_member_id' => $this->memberIdOrNull($cMember->getCMemberIdInvite()),
     430            'created_at'       => $cMember->getRDate(),
     431            'updated_at'       => $cMember->getUDatetime(),
     432            'is_active'        => !$cMember->getIsLoginRejected(),
    431433            );
    432         if ($cMember->getCMemberIdInvite() && in_array($cMember->getCMemberIdInvite(), $this->memberIds))
    433         {
    434           $param['invite_member_id'] = $cMember->getCMemberIdInvite();
    435         }
    436434
    437435        $this->insertInto('Member', $param);
     
    445443  protected function convertMemberConfig()
    446444  {
    447     $this->connectTo3();
    448 
    449445    $offset = 0;
    450446    while ($cMemberSecures = $this->getModelsIterator('CMemberSecure', 100, $offset))
     
    453449      {
    454450        // NOTICE: ignore if the member isn't exist
    455         if (!in_array($cMemberSecure->getCMemberId(), $this->memberIds))
     451        $this->connectTo2();
     452        if (!$cMember = $this->selectOne('CMember', $cMemberSecure->getCMemberId()))
    456453        {
    457454          $cMemberSecure->free();
    458455          continue;
    459456        }
     457        $this->connectTo3();
    460458
    461459        // common parameters
    462460        $param = array(
    463             'member_id' => $cMemberSecure->getCMemberId(),
     461            'member_id'  => $cMemberSecure->getCMemberId(),
    464462            'created_at' => $this->date,
    465463            'updated_at' => $this->date,
     
    470468            'pc_address'     => $this->decrypt($cMemberSecure->getPcAddress()),
    471469            'password'       => $cMemberSecure->getHashedPassword(),
    472             'mobile_address' => $cMemberSecure->getKtaiAddress(),
    473             'mobile_uid'     => $cMemberSecure->getEasyAccessId(),
    474             'lastLogin'      => $cMember->getAccessDate(),
     470            'mobile_address' => $this->orNull($cMemberSecure->getKtaiAddress()),
     471            'mobile_uid'     => $this->orNull($cMemberSecure->getEasyAccessId()),
     472            'lastLogin'      => $this->orNull($cMember->getAccessDate()),
    475473            );
    476474
     
    502500              'member_id'      => $cMember->getCMemberId(),
    503501              'file_id'        => $fileId,
    504               'image_filename' => $cMember->$getImageFilename(),
    505502              'is_primary'     => $cMember->getImageFilename() === $cMember->$getImageFilename(),
    506503              'created_at'     => $this->date,
     
    631628        ->fetchOne();
    632629
    633       $profileOptionTranslation->setValue($translation);
    634       $profileOptionTranslation->save();
    635 
    636       $profileOptionTranslation->free();
     630      if ($profileOptionTranslation)
     631      {
     632        $profileOptionTranslation->setValue($translation);
     633        $profileOptionTranslation->save();
     634        $profileOptionTranslation->free();
     635      }
    637636    }
    638637
     
    651650      {
    652651        // NOTICE: ignore if the member isn't exist
    653         if (!in_array($cMemberProfile->getCMemberId(), $this->memberIds))
     652        if (!$this->isExistMember($cMemberProfile->getCMemberId()))
    654653        {
    655654          $cMemberProfile->free();
     
    751750              'member_id_from' => $cFriend->getCMemberIdFrom(),
    752751              'member_id_to'   => $cFriend->getCMemberIdTo(),
    753               'datetime'       => $cFriend->getRDatetime(),
    754752              'is_friend'      => true,
     753              'created_at'     => $cFriend->getRDatetime(),
     754              'updated_at'     => $cFriend->getRDatetime(),
    755755              ));
    756756        $cFriend->free();
     
    767767              'member_id_from' => $cFriendConfirm->getCMemberIdFrom(),
    768768              'member_id_to'   => $cFriendConfirm->getCMemberIdTo(),
    769               'datetime'       => $cFriendConfirm->getRDatetime(),
    770769              'is_friend_pre'  => true,
     770              'created_at'     => $cFriendConfirm->getRDatetime(),
     771              'updated_at'     => $cFriendConfirm->getRDatetime(),
    771772              ));
    772773        $cFriendConfirm->free();
     
    783784              'member_id_from'  => $cAccessBlock->getCMemberId(),
    784785              'member_id_to'    => $cAccessBlock->getCMemberIdBlock(),
    785               'datetime'        => $cAccessBlock->getRDatetime(),
    786786              'is_access_block' => true,
     787              'created_at'      => $cAccessBlock->getRDatetime(),
     788              'updated_at'      => $cAccessBlock->getRDatetime(),
    787789              ));
    788790        $cAccessBlock->free();
     
    794796  protected function _updateMemberRelationship($param = array())
    795797  {
     798    // NOTICE: ignore if the members isn't exist
     799    if (!$this->isExistMember($param['member_id_from']) || !$this->isExistMember($param['member_id_to']))
     800    {
     801      return;
     802    }
     803
    796804    // NOTICE: ignore if member_id_from is equal to member_id_to
    797805    if ($param['member_id_from'] === $param['member_id_to'])
     
    827835    foreach ($cCommuTopics as $cCommuTopic)
    828836    {
     837      // NOTICE: ignore if the community has this topic isn't exist
     838      if (!$this->isExistCommunity($cCommuTopic->getCCommuId()))
     839      {
     840        $cCommuTopic->free();
     841        continue;
     842      }
     843
    829844      $param = array(
    830         'id'           => $cCommuTopic->getCCommuTopicId(),
    831         'community_id' => $cCommuTopic->getCCommuId(),
    832         'name'         => $cCommuTopic->getName(),
     845        'id'               => $cCommuTopic->getCCommuTopicId(),
     846        'community_id'     => $cCommuTopic->getCCommuId(),
     847        'name'             => $cCommuTopic->getName(),
     848        'member_id'        => $this->memberIdOrNull($cCommuTopic->getCMemberId()),
    833849        'topic_updated_at' => $cCommuTopic->getUDatetime(),
    834         'created_at'   => $cCommuTopic->getRDatetime(),
    835         'updated_at'   => $cCommuTopic->getUDatetime(),
     850        'created_at'       => $cCommuTopic->getRDatetime(),
     851        'updated_at'       => $cCommuTopic->getUDatetime(),
    836852      );
    837       if (!in_array($cCommuTopic->getCMemberId(), $this->memberIds))
    838       {
    839         $param['member_id'] = $cCommuTopic->getCMemberId();
    840       }
    841853
    842854      $communityTopic = $this->insertInto('CommunityTopic', $param, true);
     855      $communityTopic->save();
    843856
    844857      $this->connectTo2();
     
    859872          $this->insertInto('CommunityTopicComment', array(
    860873            'community_topic_id' => $comment->getCCommuTopicId(),
    861             'member_id'          => $comment->getCMemberId(),
     874            'member_id'          => $this->memberIdOrNull($comment->getCMemberId()),
    862875            'body'               => $comment->getBody(),
    863876            'created_at'         => $comment->getRDatetime(),
     
    884897    foreach ($cCommuEvents as $cCommuEvent)
    885898    {
     899      // NOTICE: ignore if the community has this event isn't exist
     900      if (!$this->isExistCommunity($cCommuEvent->getCCommuId()))
     901      {
     902        $cCommuEvent->free();
     903        continue;
     904      }
     905
    886906      $param = array(
    887         'id'           => $cCommuEvent->getCCommuTopicId(),
    888         'community_id' => $cCommuEvent->getCCommuId(),
    889         'name'         => $cCommuEvent->getName(),
    890         'event_updated_at' => $cCommuEvent->getUDatetime(),
    891         'open_date'    => $cCommuEvent->getOpenDate(),
    892         'open_date_comment' => $cCommuEvent->getOpenDateComment(),
    893         'application_deadline' => $cCommuEvent->getInvitePeriod(),
    894         'capacity'         => $cCommuEvent->getCapacity(),
    895         'created_at'       => $cCommuEvent->getRDatetime(),
    896         'updated_at'       => $cCommuEvent->getUDatetime(),
     907        'id'                   => $cCommuEvent->getCCommuTopicId(),
     908        'community_id'         => $cCommuEvent->getCCommuId(),
     909        'name'                 => $cCommuEvent->getName(),
     910        'member_id'            => $this->memberIdOrNull($cCommuEvent->getCMemberId()),
     911        'event_updated_at'     => $this->orNull($cCommuEvent->getUDatetime()),
     912        'open_date'            => $this->orNull($cCommuEvent->getOpenDate()),
     913        'open_date_comment'    => $this->orNull($cCommuEvent->getOpenDateComment()),
     914        'application_deadline' => $this->orNull($cCommuEvent->getInvitePeriod()),
     915        'capacity'             => $this->orNull($cCommuEvent->getCapacity()),
     916        'created_at'           => $cCommuEvent->getRDatetime(),
     917        'updated_at'           => $cCommuEvent->getUDatetime(),
    897918      );
    898       if (!in_array($cCommuEvent->getCMemberId(), $this->memberIds))
    899       {
    900         $param['member_id'] = $cCommuEvent->getCMemberId();
    901       }
    902919
    903920      $communityEvent = $this->insertInto('CommunityEvent', $param, true);
     921      $communityEvent->save();
    904922
    905923      $this->connectTo2();
     
    957975      {
    958976        // NOTICE: ignore if the member isn't exist
    959         if (!in_array($cDiary->getCMemberId(), $this->memberIds))
     977        if (!$this->isExistMember($cDiary->getCMemberId()))
    960978        {
    961979          $cDiary->free();
     
    972990          'updated_at'  => $cDiary->getUDatetime(),
    973991        ), true);
     992        $diary->save();
    974993
    975994        for ($i = 1; $i <= 3; ++$i)
     
    10021021  protected function convertDiaryCommentAndImage()
    10031022  {
    1004     $this->connectTo2();
    1005     $cDiaryComments = Doctrine::getTable('CDiaryComment')->findAll();
    10061023    $this->connectTo3();
    10071024
     
    10141031        if (!$this->isExist('Diary', $cDiaryComment->getCDiaryId()))
    10151032        {
     1033          $cDiaryComment->free();
    10161034          continue;
    10171035        }
    10181036
    10191037        // NOTICE: ignore if that's member isn't exist
    1020         if (!in_array($cDiaryComment->getCMemberId(), $this->memberIds))
    1021         {
     1038        if (!$this->isExistMember($cDiaryComment->getCMemberId()))
     1039        {
     1040          $cDiaryComment->free();
    10221041          continue;
    10231042        }
     
    10901109          'updated_at' => $cMessage->getRDatetime(),
    10911110        ), true);
     1111        $messageSendList->save();
    10921112
    10931113        // create DeletedMessage
     
    11631183  }
    11641184
     1185  protected function convertAshiato()
     1186  {
     1187    $this->connectTo3();
     1188
     1189    $offset = 0;
     1190    while ($cAshiatos = $this->getModelsIterator('CAshiato', 100, $offset))
     1191    {
     1192      foreach ($cAshiatos as $cAshiato)
     1193      {
     1194        $param = array(
     1195          'id'             => $cAshiato->getCAshiatoId(),
     1196          'member_id_from' => $this->memberIdOrNull($cAshiato->getCMemberIdFrom()),
     1197          'member_id_to'   => $this->memberIdOrNull($cAshiato->getCMemberIdTo()),
     1198          'r_date'         => $cAshiato->getRDate(),
     1199          'created_at'     => $cAshiato->getRDatetime(),
     1200          'updated_at'     => $cAshiato->getRDatetime(),
     1201        );
     1202
     1203        $this->insertInto('Ashiato', $param);
     1204        $cAshiato->free();
     1205      }
     1206      $offset += 100;
     1207    }
     1208  }
     1209
    11651210  /**
    11661211   * Functions
     
    11991244      {
    12001245        $this->mapFileNameToId[$name] = $file->getId();
     1246        $file->free();
     1247      }
     1248      else
     1249      {
     1250        $this->mapFileNameToId[$name] = null;
    12011251      }
    12021252    }
    12031253
    12041254    return $this->mapFileNameToId[$name];
     1255  }
     1256
     1257  protected function isExistMember($memberId)
     1258  {
     1259    return in_array($memberId, $this->memberIds);
     1260  }
     1261
     1262  protected function isExistCommunity($communityId)
     1263  {
     1264    return in_array($communityId, $this->communityIds);
     1265  }
     1266
     1267  protected function memberIdOrNull($memberId)
     1268  {
     1269    return $this->isExistMember($memberId) ? $memberId : null;
    12051270  }
    12061271
     
    12251290    foreach ($configs as $name => $value)
    12261291    {
    1227       if (!$value)
    1228       {
    1229         continue;
    1230       }
    1231 
    12321292      $this->insertInto($tableName, array_merge($param, array(
    12331293        'name'  => $name,
     
    13681428  }
    13691429
     1430  protected function orNull($value = null)
     1431  {
     1432    return $value ? $value : null;
     1433  }
     1434
    13701435  /**
    13711436   * SQL like operations
     
    14051470    foreach ($param as $field => $value)
    14061471    {
    1407       $methodName = $this->makeCamelCase('set'.$field);
    1408       $record->{$this->makeCamelCase('set_'.$field)}($value);
     1472      if (!is_null($value))
     1473      {
     1474        $methodName = $this->makeCamelCase('set'.$field);
     1475        $record->{$this->makeCamelCase('set_'.$field)}($value);
     1476      }
    14091477    }
    14101478
Note: See TracChangeset for help on using the changeset viewer.