Changeset 12849
- Timestamp:
- Sep 7, 2009, 7:01:08 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
OpenPNE3/branches/fukamachi/db-convert-from-2.x/lib/task/openpneUpgradeFrom2Task.class.php
r12840 r12849 11 11 class openpneUpgradeFrom2Task extends sfDoctrineBaseTask 12 12 { 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; 27 29 28 30 protected function configure() … … 48 50 $pluginInstall->run(array('opCommunityTopicPlugin'), array('--stability=beta')); 49 51 //$pluginInstall->run(array('opMessagePlugin'), array('--stability=beta')); 50 //$pluginInstall->run(array('opAshiatoPlugin'), array('--stability=beta'));52 $pluginInstall->run(array('opAshiatoPlugin'), array('--stability=beta')); 51 53 52 54 // install OpenPNE3 … … 99 101 100 102 // 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'); 102 104 103 105 foreach ($tables as $table) … … 129 131 print "converting ProfileOption : ".memory_get_usage()."\n"; 130 132 $this->convertProfileOption(); 131 //print "converting MemberProfile : ".memory_get_usage()."\n";132 //$this->convertMemberProfile();133 print "converting MemberProfile : ".memory_get_usage()."\n"; 134 $this->convertMemberProfile(); 133 135 print "converting MemberRelationship : ".memory_get_usage()."\n"; 134 136 $this->convertMemberRelationship(); 135 print "converting CommunityTopic AndComment : ".memory_get_usage()."\n";137 print "converting CommunityTopic and CommunityTopicComment : ".memory_get_usage()."\n"; 136 138 $this->convertCommunityTopicAndComment(); 137 print "converting CommunityEvent AndComment : ".memory_get_usage()."\n";139 print "converting CommunityEvent and CommunityEventComment : ".memory_get_usage()."\n"; 138 140 $this->convertCommunityEventAndComment(); 139 print "converting Diary AndImage : ".memory_get_usage()."\n";141 print "converting Diary and DiaryImage : ".memory_get_usage()."\n"; 140 142 $this->convertDiaryAndImage(); 141 print "converting DiaryComment AndImage : ".memory_get_usage()."\n";143 print "converting DiaryComment and DiaryCommentImage : ".memory_get_usage()."\n"; 142 144 $this->convertDiaryCommentAndImage(); 143 //print "converting Message Tables : ".memory_get_usage()."\n";145 //print "converting Message tables : ".memory_get_usage()."\n"; 144 146 //$this->convertMessageTables(); 147 print "converting Ashiato : ".memory_get_usage()."\n"; 148 $this->convertAshiato(); 145 149 146 150 // delete models' cache … … 366 370 $this->createConfigs('CommunityConfig', $param, $configs); 367 371 372 $this->mapCommunityAdminId[$cCommu->getCCommuId()] = $cCommu->getCMemberIdAdmin(); 373 $this->communityIds[] = $cCommu->getCCommuId(); 368 374 $cCommu->free(); 369 375 } … … 382 388 { 383 389 // NOTICE: ignore if the community this member joins is not exist 384 if (!$this->isExist ('Community',$cCommuMember->getCCommuId()))390 if (!$this->isExistCommunity($cCommuMember->getCCommuId())) 385 391 { 386 392 $cCommuMember->free(); … … 396 402 ); 397 403 $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()]) 404 405 { 405 406 $param['position'] = 'admin'; … … 424 425 { 425 426 $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(), 431 433 ); 432 if ($cMember->getCMemberIdInvite() && in_array($cMember->getCMemberIdInvite(), $this->memberIds))433 {434 $param['invite_member_id'] = $cMember->getCMemberIdInvite();435 }436 434 437 435 $this->insertInto('Member', $param); … … 445 443 protected function convertMemberConfig() 446 444 { 447 $this->connectTo3();448 449 445 $offset = 0; 450 446 while ($cMemberSecures = $this->getModelsIterator('CMemberSecure', 100, $offset)) … … 453 449 { 454 450 // 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())) 456 453 { 457 454 $cMemberSecure->free(); 458 455 continue; 459 456 } 457 $this->connectTo3(); 460 458 461 459 // common parameters 462 460 $param = array( 463 'member_id' => $cMemberSecure->getCMemberId(),461 'member_id' => $cMemberSecure->getCMemberId(), 464 462 'created_at' => $this->date, 465 463 'updated_at' => $this->date, … … 470 468 'pc_address' => $this->decrypt($cMemberSecure->getPcAddress()), 471 469 '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()), 475 473 ); 476 474 … … 502 500 'member_id' => $cMember->getCMemberId(), 503 501 'file_id' => $fileId, 504 'image_filename' => $cMember->$getImageFilename(),505 502 'is_primary' => $cMember->getImageFilename() === $cMember->$getImageFilename(), 506 503 'created_at' => $this->date, … … 631 628 ->fetchOne(); 632 629 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 } 637 636 } 638 637 … … 651 650 { 652 651 // NOTICE: ignore if the member isn't exist 653 if (! in_array($cMemberProfile->getCMemberId(), $this->memberIds))652 if (!$this->isExistMember($cMemberProfile->getCMemberId())) 654 653 { 655 654 $cMemberProfile->free(); … … 751 750 'member_id_from' => $cFriend->getCMemberIdFrom(), 752 751 'member_id_to' => $cFriend->getCMemberIdTo(), 753 'datetime' => $cFriend->getRDatetime(),754 752 'is_friend' => true, 753 'created_at' => $cFriend->getRDatetime(), 754 'updated_at' => $cFriend->getRDatetime(), 755 755 )); 756 756 $cFriend->free(); … … 767 767 'member_id_from' => $cFriendConfirm->getCMemberIdFrom(), 768 768 'member_id_to' => $cFriendConfirm->getCMemberIdTo(), 769 'datetime' => $cFriendConfirm->getRDatetime(),770 769 'is_friend_pre' => true, 770 'created_at' => $cFriendConfirm->getRDatetime(), 771 'updated_at' => $cFriendConfirm->getRDatetime(), 771 772 )); 772 773 $cFriendConfirm->free(); … … 783 784 'member_id_from' => $cAccessBlock->getCMemberId(), 784 785 'member_id_to' => $cAccessBlock->getCMemberIdBlock(), 785 'datetime' => $cAccessBlock->getRDatetime(),786 786 'is_access_block' => true, 787 'created_at' => $cAccessBlock->getRDatetime(), 788 'updated_at' => $cAccessBlock->getRDatetime(), 787 789 )); 788 790 $cAccessBlock->free(); … … 794 796 protected function _updateMemberRelationship($param = array()) 795 797 { 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 796 804 // NOTICE: ignore if member_id_from is equal to member_id_to 797 805 if ($param['member_id_from'] === $param['member_id_to']) … … 827 835 foreach ($cCommuTopics as $cCommuTopic) 828 836 { 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 829 844 $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()), 833 849 '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(), 836 852 ); 837 if (!in_array($cCommuTopic->getCMemberId(), $this->memberIds))838 {839 $param['member_id'] = $cCommuTopic->getCMemberId();840 }841 853 842 854 $communityTopic = $this->insertInto('CommunityTopic', $param, true); 855 $communityTopic->save(); 843 856 844 857 $this->connectTo2(); … … 859 872 $this->insertInto('CommunityTopicComment', array( 860 873 'community_topic_id' => $comment->getCCommuTopicId(), 861 'member_id' => $ comment->getCMemberId(),874 'member_id' => $this->memberIdOrNull($comment->getCMemberId()), 862 875 'body' => $comment->getBody(), 863 876 'created_at' => $comment->getRDatetime(), … … 884 897 foreach ($cCommuEvents as $cCommuEvent) 885 898 { 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 886 906 $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(), 897 918 ); 898 if (!in_array($cCommuEvent->getCMemberId(), $this->memberIds))899 {900 $param['member_id'] = $cCommuEvent->getCMemberId();901 }902 919 903 920 $communityEvent = $this->insertInto('CommunityEvent', $param, true); 921 $communityEvent->save(); 904 922 905 923 $this->connectTo2(); … … 957 975 { 958 976 // NOTICE: ignore if the member isn't exist 959 if (! in_array($cDiary->getCMemberId(), $this->memberIds))977 if (!$this->isExistMember($cDiary->getCMemberId())) 960 978 { 961 979 $cDiary->free(); … … 972 990 'updated_at' => $cDiary->getUDatetime(), 973 991 ), true); 992 $diary->save(); 974 993 975 994 for ($i = 1; $i <= 3; ++$i) … … 1002 1021 protected function convertDiaryCommentAndImage() 1003 1022 { 1004 $this->connectTo2();1005 $cDiaryComments = Doctrine::getTable('CDiaryComment')->findAll();1006 1023 $this->connectTo3(); 1007 1024 … … 1014 1031 if (!$this->isExist('Diary', $cDiaryComment->getCDiaryId())) 1015 1032 { 1033 $cDiaryComment->free(); 1016 1034 continue; 1017 1035 } 1018 1036 1019 1037 // 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(); 1022 1041 continue; 1023 1042 } … … 1090 1109 'updated_at' => $cMessage->getRDatetime(), 1091 1110 ), true); 1111 $messageSendList->save(); 1092 1112 1093 1113 // create DeletedMessage … … 1163 1183 } 1164 1184 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 1165 1210 /** 1166 1211 * Functions … … 1199 1244 { 1200 1245 $this->mapFileNameToId[$name] = $file->getId(); 1246 $file->free(); 1247 } 1248 else 1249 { 1250 $this->mapFileNameToId[$name] = null; 1201 1251 } 1202 1252 } 1203 1253 1204 1254 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; 1205 1270 } 1206 1271 … … 1225 1290 foreach ($configs as $name => $value) 1226 1291 { 1227 if (!$value)1228 {1229 continue;1230 }1231 1232 1292 $this->insertInto($tableName, array_merge($param, array( 1233 1293 'name' => $name, … … 1368 1428 } 1369 1429 1430 protected function orNull($value = null) 1431 { 1432 return $value ? $value : null; 1433 } 1434 1370 1435 /** 1371 1436 * SQL like operations … … 1405 1470 foreach ($param as $field => $value) 1406 1471 { 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 } 1409 1477 } 1410 1478
Note: See TracChangeset
for help on using the changeset viewer.