1111
1212use Doctrine \DBAL \Schema \Schema ;
1313use Doctrine \DBAL \Types \Type ;
14+ use Exception ;
1415use OCA \Polls \AppConstants ;
1516use OCA \Polls \Migration \TableSchema ;
1617use OCP \DB \QueryBuilder \IQueryBuilder ;
@@ -379,11 +380,16 @@ public function migrateOptionsToHash(): array {
379380 $ count = 0 ;
380381 if ($ table ->hasColumn ('poll_option_hash ' )) {
381382 foreach ($ this ->optionMapper ->getAll () as $ option ) {
382- $ option ->syncOption ();
383- // $option->setPollOptionHash(hash('md5', $option->getPollId() . $option->getPollOptionText() . $option->getTimestamp()));
384-
385- $ this ->optionMapper ->update ($ option );
386- $ count ++;
383+ try {
384+ $ option ->syncOption ();
385+ // $option->setPollOptionHash(hash('md5', $option->getPollId() . $option->getPollOptionText() . $option->getTimestamp()));
386+
387+ $ this ->optionMapper ->update ($ option );
388+ $ count ++;
389+ } catch (Exception $ e ) {
390+ $ messages [] = 'Skip hash update - Error updating option hash for optionId ' . $ option ->getId ();
391+ $ this ->logger ->error ('Error updating option hash for optionId {id} ' , ['id ' => $ option ->getId (), 'message ' => $ e ->getMessage ()]);
392+ }
387393 }
388394
389395 $ this ->logger ->info ('Updated {number} hashes in {db} ' , ['number ' => $ count ,'db ' => $ this ->dbPrefix . OptionMapper::TABLE ]);
@@ -401,9 +407,14 @@ public function migrateOptionsToHash(): array {
401407 $ count = 0 ;
402408 if ($ table ->hasColumn ('vote_option_hash ' )) {
403409 foreach ($ this ->voteMapper ->getAll () as $ vote ) {
404- $ vote ->setVoteOptionHash (hash ('md5 ' , $ vote ->getPollId () . $ vote ->getUserId () . $ vote ->getVoteOptionText ()));
405- $ this ->voteMapper ->update ($ vote );
406- $ count ++;
410+ try {
411+ $ vote ->setVoteOptionHash (hash ('md5 ' , $ vote ->getPollId () . $ vote ->getUserId () . $ vote ->getVoteOptionText ()));
412+ $ this ->voteMapper ->update ($ vote );
413+ $ count ++;
414+ } catch (Exception $ e ) {
415+ $ messages [] = 'Skip hash update - Error updating option hash for voteId ' . $ vote ->getId ();
416+ $ this ->logger ->error ('Error updating option hash for voteId {id} ' , ['id ' => $ vote ->getId (), 'message ' => $ e ->getMessage ()]);
417+ }
407418 }
408419
409420 $ this ->logger ->info ('Updated {number} hashes in {db} ' , ['number ' => $ count , 'db ' => $ this ->dbPrefix . VoteMapper::TABLE ]);
0 commit comments