@@ -84,28 +84,34 @@ public function apply()
8484 $ this ->tokenCollection ->addFieldToSelect ('entity_id ' );
8585 $ this ->tokenCollection ->addFieldToSelect ('secret ' );
8686 $ this ->tokenCollection ->addFieldToSelect ('type ' );
87- $ this ->tokenCollection ->getSelect ()->limit (self ::BATCH_SIZE );
88- $ collectionItems = $ this ->tokenCollection ->getItems ();
87+ $ this ->tokenCollection ->setPageSize (self ::BATCH_SIZE );
8988 $ connection = $ this ->tokenResourceModel ->getConnection ();
90-
91- /** @var $token Token */
92- foreach ($ collectionItems as $ token ) {
93- $ existingSecret = $ token ->getSecret ();
94- $ entityId = $ token ->getEntityId ();
95- $ type = strtolower ($ token ->getType ());
96-
97- if ($ entityId && $ existingSecret && $ type === TokenModel::TYPE_ACCESS ) {
98- if (strlen ($ existingSecret ) <= OauthHelper::LENGTH_TOKEN_SECRET ) {
99- $ data = ['secret ' => $ this ->encryptor ->encrypt ($ existingSecret )];
100- $ where = ['entity_id = ? ' => $ entityId , 'type = ? ' => 'access ' ];
101- try {
102- $ connection ->update ($ this ->tokenResourceModel ->getMainTable (), $ data , $ where );
103- } catch (\Exception $ exception ) {
104- $ this ->logger ->critical ($ exception ->getMessage ());
105- return $ this ;
89+ $ pages = $ this ->tokenCollection ->getLastPageNumber ();
90+ $ tableName = $ this ->tokenResourceModel ->getMainTable ();
91+
92+ for ($ currentPage = 1 ; $ currentPage <= $ pages ; $ currentPage ++) {
93+ $ this ->tokenCollection ->setCurPage ($ currentPage );
94+
95+ /** @var $token Token */
96+ foreach ($ this ->tokenCollection as $ token ) {
97+ $ existingSecret = $ token ->getSecret ();
98+ $ entityId = $ token ->getEntityId ();
99+ $ type = strtolower ($ token ->getType ());
100+
101+ if ($ entityId && $ existingSecret && $ type === TokenModel::TYPE_ACCESS ) {
102+ if (strlen ($ existingSecret ) <= OauthHelper::LENGTH_TOKEN_SECRET ) {
103+ $ data = ['secret ' => $ this ->encryptor ->encrypt ($ existingSecret )];
104+ $ where = ['entity_id = ? ' => $ entityId , 'type = ? ' => 'access ' ];
105+ try {
106+ $ connection ->update ($ tableName , $ data , $ where );
107+ } catch (\Exception $ exception ) {
108+ $ this ->logger ->critical ($ exception ->getMessage ());
109+ return $ this ;
110+ }
106111 }
107112 }
108113 }
114+ $ this ->tokenCollection ->clear ();
109115 }
110116 return $ this ;
111117 }
0 commit comments