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

Changeset 12763


Ignore:
Timestamp:
Aug 26, 2009, 7:57:15 PM (13 years ago)
Author:
fukamachi
Message:

db converter - fixed convertMemberProfile for performance and debugging. and add note of Notice

File:
1 edited

Legend:

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

    r12760 r12763  
    233233      ->fetchOne();
    234234
     235    // NOTICE: ignore if the file with same name had saved
    235236    if ($dupNamedFile)
    236237    {
    237238      $dupNamedFile->free();
     239
    238240      return;
    239241    }
     
    335337
    336338      $community->setName($cCommu->getName());
    337       // add index if already created same name community
     339      // NOTICE: add index if already created same name community
    338340      if ($this->_isDuplicateCommunityName($cCommu->getName()))
    339341      {
     
    594596    }
    595597
     598    // NOTICE: ignore if the member image isn't exist
     599    if (!($fileId = $this->getFileIdByName($param['image_filename'])))
     600    {
     601      return;
     602    }
     603
    596604    $memberImage = new TempMemberImage();
    597605    $memberImage->setMemberId($param['member_id']);
    598     $memberImage->setFileId($this->getFileIdByName($param['image_filename']));
     606    $memberImage->setFileId($fileId);
    599607    if ($param['image_filename'] === $param['primary_image'])
    600608    {
     
    752760  protected function convertMemberProfile()
    753761  {
    754     $this->connectTo2();
    755     $cMemberProfiles = Doctrine::getTable('CMemberProfile')->findAll();
    756762    $this->connectTo3();
    757763    $this->clearDbTable('MemberProfile');
    758764    $treeProfile = Doctrine::getTable('MemberProfile')->getTree();
    759765
    760     foreach ($cMemberProfiles as $cMemberProfile)
    761     {
    762       $memberProfile = $this->_getMemberProfile(array(
    763         'id'                => $cMemberProfile->getCMemberProfileId(),
    764         'member_id'         => $cMemberProfile->getCMemberId(),
    765         'profile_id'        => $cMemberProfile->getCProfileId(),
    766         'profile_option_id' => $cMemberProfile->getCProfileOptionId(),
    767         'value'             => $cMemberProfile->getValue(),
    768         'public_flag'       => $cMemberProfile->getPublicFlag(),
    769       ));
    770 
    771       $memberProfile->save();
    772 
    773       $this->connectTo2();
    774       $cMember = Doctrine::getTable('CMember')->find($cMemberProfile->getCMemberId());
    775       $this->connectTo3();
    776 
    777       $birthdayRoot = new TempMemberProfile();
    778 
    779       $birthdayYear = $this->_getMemberProfile(array(
    780         'member_id'   => $cMemberProfile->getCMemberId(),
    781         'profile_id'  => $this->birthdayProfileId,
    782         'value'       => $cMember->getBirthYear(),
    783         'public_flag' => $cMember->getPublicFlagBirthYear(),
    784       ));
    785       $birthdayMonth = $this->_getMemberProfile(array(
    786         'member_id'    => $cMemberProfile->getCMemberId(),
    787         'profile_id'   => $this->birthdayProfileId,
    788         'value'        => $cMember->getBirthMonth(),
    789         'public_flag'  => $cMember->getPublicFlagBirthMonthDay(),
    790       ));
    791       $birthdayDay = $this->_getMemberProfile(array(
    792         'member_id'    => $cMemberProfile->getCMemberId(),
    793         'profile_id'   => $this->birthdayProfileId,
    794         'value'        => $cMember->getBirthDay(),
    795         'public_flag'  => $cMember->getPublicFlagBirthMonthDay(),
    796       ));
    797 
    798       $birthdayYear->getNode()->insertAsLastChildOf($birthdayRoot);
    799       $birthdayMonth->getNode()->insertAsLastChildOf($birthdayRoot);
    800       $birthdayDay->getNode()->insertAsLastChildOf($birthdayRoot);
    801       $birthdayRoot->save();
    802 
    803       $cMember->free();
    804       $memberProfile->free();
    805       $birthdayRoot->free();
     766    $offset = 0;
     767    while ($cMemberProfiles = $this->getModelsIterator('CMemberProfile', 100, $offset))
     768    {
     769      foreach ($cMemberProfiles as $cMemberProfile)
     770      {
     771        $memberProfile = $this->_getMemberProfile(array(
     772          'member_id'         => $cMemberProfile->getCMemberId(),
     773          'profile_id'        => $cMemberProfile->getCProfileId(),
     774          'profile_option_id' => $cMemberProfile->getCProfileOptionId(),
     775          'value'             => $cMemberProfile->getValue(),
     776          'public_flag'       => $cMemberProfile->getPublicFlag(),
     777        ));
     778
     779        $memberProfile->save();
     780
     781        $this->connectTo2();
     782        $cMember = Doctrine::getTable('CMember')->find($cMemberProfile->getCMemberId());
     783        $this->connectTo3();
     784
     785        $birthdayRoot = $this->_getMemberProfile(array(
     786          'member_id'   => $cMemberProfile->getCMemberId(),
     787          'profile_id'  => $this->birthdayProfileId,
     788        ));
     789        $birthdayYear = $this->_getMemberProfile(array(
     790          'member_id'   => $cMemberProfile->getCMemberId(),
     791          'profile_id'  => $this->birthdayProfileId,
     792          'value'       => $cMember->getBirthYear(),
     793          'public_flag' => $cMember->getPublicFlagBirthYear(),
     794        ));
     795        $birthdayMonth = $this->_getMemberProfile(array(
     796          'member_id'    => $cMemberProfile->getCMemberId(),
     797          'profile_id'   => $this->birthdayProfileId,
     798          'value'        => $cMember->getBirthMonth(),
     799          'public_flag'  => $cMember->getPublicFlagBirthMonthDay(),
     800        ));
     801        $birthdayDay = $this->_getMemberProfile(array(
     802          'member_id'    => $cMemberProfile->getCMemberId(),
     803          'profile_id'   => $this->birthdayProfileId,
     804          'value'        => $cMember->getBirthDay(),
     805          'public_flag'  => $cMember->getPublicFlagBirthMonthDay(),
     806        ));
     807
     808        $birthdayYear->getNode()->insertAsLastChildOf($birthdayRoot);
     809        $birthdayMonth->getNode()->insertAsLastChildOf($birthdayRoot);
     810        $birthdayDay->getNode()->insertAsLastChildOf($birthdayRoot);
     811        $birthdayRoot->save();
     812
     813        $cMemberProfile->free();
     814        $cMember->free();
     815        $memberProfile->free();
     816        $birthdayRoot->free();
     817      }
     818      $offset += 100;
    806819    }
    807820  }
     
    809822  protected function _getMemberProfile($param = array())
    810823  {
     824    // NOTICE: ignore if c_member_profile.c_profile_id = 0
     825    if (!array_key_exists('profile_id', $param) || !$param['profile_id'])
     826    {
     827      return;
     828    }
     829
    811830    $memberProfile = new TempMemberProfile();
    812     if (array_key_exists('id', $param))
    813     {
    814       $memberProfile->setId($param['id']);
    815     }
    816831    $memberProfile->setMemberId($param['member_id']);
    817832    $memberProfile->setProfileId($param['profile_id']);
    818     if (array_key_exists('profile_option_id', $param))
     833    if (array_key_exists('profile_option_id', $param) && $param['profile_option_id'])
    819834    {
    820835      $memberProfile->setProfileOptionId($param['profile_option_id']);
    821836    }
    822     $memberProfile->setValue($param['value']);
    823     $memberProfile->setPublicFlag($param['public_flag']);
     837    if (array_key_exists('value', $param) && $param['value'])
     838    {
     839      $memberProfile->setValue($param['value']);
     840    }
     841    if (array_key_exists('public_flag', $param) && $param['public_flag'])
     842    {
     843      $memberProfile->setPublicFlag($param['public_flag']);
     844    }
    824845    $memberProfile->setCreatedAt($this->date);
    825846    $memberProfile->setUpdatedAt($this->date);
     
    955976    if ($file)
    956977    {
    957       return $file->getId();
     978      $id = $file->getId();
     979      $file->free();
     980
     981      return $id;
    958982    }
    959983  }
Note: See TracChangeset for help on using the changeset viewer.