/** * This method deletes all cards within supplied User $from & saves those to User $into. * * @param UserRow $from * @param UserRow $into * * @return void */ protected function transferLibraryCards(UserRow $from, UserRow $into) { $libCards = $from->getAllUserLibraryCards(); foreach ($libCards as $libCard) { // Because eppn column is across user_card table unique, we need to mark it to deletion // in order to be able of recreating it after any failure while transferring $this->setLibCardDeletionFlag($libCard, true); try { $into->createLibraryCard($libCard->cat_username, $libCard->home_library, $libCard->eppn, $libCard->card_name, $this->canConsolidateMoreTimes); } catch (AuthException $e) { // Something went wrong - restore libCard flagged for deletion $this->setLibCardDeletionFlag($libCard, false); throw $e; } $from->deleteLibraryCardRow($libCard, false); } }