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

Changeset 12744


Ignore:
Timestamp:
Aug 24, 2009, 2:25:57 PM (13 years ago)
Author:
fukamachi
Message:

db converter - revert r12743. and added a convert method for member_image table

File:
1 edited

Legend:

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

    r12743 r12744  
    9696    $this->convertCommunityAndCommunityConfig();
    9797    $this->convertCommunityMember();
    98     $this->convertCommunity();
    9998    $this->convertMember();
    10099    $this->convertMemberConfig();
     100    $this->convertMemberImage();
    101101
    102102    // delete models' cache
     
    229229      $community->setId($cCommu->getCCommuId());
    230230      $community->setName($cCommu->getName());
    231 
    232       if ($cCommu->getImageFilename())
    233       {
    234         $this->connectTo2();
    235         $fileId = Doctrine::getTable('CFile')->createQuery()
    236           ->select('c_file_id')
    237           ->where('filename = ?', $cCommu->getImageFilename())
    238           ->fetchOne();
    239         $this->connectTo3();
    240         if ($file)
    241         {
    242           $community->setFileId($file->getCFileId());
    243         }
    244       }
    245 
     231      $community->setFileId($this->getFileIdByName($cCommu->getImageFilename()));
    246232      $community->setCommunityCategoryId($this->mapCategoryIds[$cCommu->getCCommuCategoryId()]);
    247233      $community->setCreatedAt($cCommu->getRDate());
     
    298284
    299285      $communityMember->save();
    300     }
    301   }
    302 
    303   protected function convertCommunity()
    304   {
    305     $this->connectTo2();
    306     $cCommus = Doctrine::getTable('CCommu')->findAll();
    307     $this->connectTo3();
    308     $this->clearDbTable('Community');
    309 
    310     foreach ($cCommus as $cCommu)
    311     {
    312       $community = new TempCommunity();
    313       $community->setId($cCommu->getCCommuId());
    314       $community->setName($cCommu->getName());
    315       if ($cCommu->getImageFilename())
    316       {
    317         $file = Doctrine::getTable('File')->createQuery()
    318           ->select('id')
    319           ->where('name = ?', $cCommu->getImageFilename())
    320           ->fetchOne();
    321         $community->setFileId($file->getId());
    322       }
    323       $community->setCommunityCategoryId($this->mapCategoryIds[$cCommu->getCCommuCategoryId()]);
    324       $community->setCreatedAt($cCommu->getRDatetime());
    325       $community->setUpdatedAt($cCommu->getUDatetime());
    326 
    327       $community->save();
    328286    }
    329287  }
     
    413371
    414372    $memberConfig->save();
     373  }
     374
     375  protected function convertMemberImage()
     376  {
     377    $this->connectTo2();
     378    $cMembers = Doctrine::getTable('CMember')->findAll();
     379    $this->connectTo3();
     380
     381    foreach ($cMembers as $cMember)
     382    {
     383      $primaryImage = $cMember->getImageFilename();
     384
     385      $this->_createMemberImage(array(
     386        'member_id'      => $cMember->getCMemberId(),
     387        'image_filename' => $cMember->getImageFilename_1(),
     388        'primary_image'  => $primaryImage,
     389      ));
     390
     391      $this->_createMemberImage(array(
     392        'member_id'      => $cMember->getCMemberId(),
     393        'image_filename' => $cMember->getImageFilename_2(),
     394        'primary_image'  => $primaryImage,
     395      ));
     396
     397      $this->_createMemberImage(array(
     398        'member_id'      => $cMember->getCMemberId(),
     399        'image_filename' => $cMember->getImageFilename_3(),
     400        'primary_image'  => $primaryImage,
     401      ));
     402    }
     403  }
     404
     405  protected function _createMemberImage($param = array())
     406  {
     407    if (!$param['image_filename'])
     408    {
     409      return;
     410    }
     411
     412    $memberImage = new TempMemberImage();
     413    $memberImage->setMemberId($param['member_id']);
     414    $memberImage->setFileId($this->getFileIdByName($param['image_filename']));
     415    if ($param['image_filename'] === $param['primary_image'])
     416    {
     417      $memberImage->setIsPrimary(true);
     418    }
     419    $memberImage->setCreatedAt($this->date);
     420    $memberImage->setUpdatedAt($this->date);
     421
     422    $memberImage->save();
    415423  }
    416424
     
    526534    return $singleton;
    527535  }
     536
     537  protected function getFileIdByName($name)
     538  {
     539    if (!$name)
     540    {
     541      return;
     542    }
     543
     544    $this->connectTo3();
     545    $file = Doctrine::getTable('File')->createQuery()
     546      ->select('id')
     547      ->where('name = ?', $name)
     548      ->fetchOne();
     549
     550    if ($file)
     551    {
     552      return $file->getId();
     553    }
     554  }
    528555}
Note: See TracChangeset for help on using the changeset viewer.