77
88namespace Magento \DataExporter \Model \Indexer ;
99
10+ use DateTime ;
1011use Magento \Framework \App \ResourceConnection ;
1112use Magento \Framework \DB \Select ;
1213
@@ -45,8 +46,10 @@ public function getAllIds(FeedIndexMetadata $metadata): ?\Generator
4546 $ connection = $ this ->resourceConnection ->getConnection ();
4647 $ lastKnownId = -1 ;
4748 $ continueReindex = true ;
49+ $ dateTime = date_create ();
50+
4851 while ($ continueReindex ) {
49- $ ids = $ connection ->fetchAll ($ this ->getIdsSelect ((int )$ lastKnownId , $ metadata ));
52+ $ ids = $ connection ->fetchAll ($ this ->getIdsSelect ((int )$ lastKnownId , $ metadata, $ dateTime ));
5053 if (empty ($ ids )) {
5154 $ continueReindex = false ;
5255 } else {
@@ -61,25 +64,37 @@ public function getAllIds(FeedIndexMetadata $metadata): ?\Generator
6164 *
6265 * @param int $lastKnownId
6366 * @param FeedIndexMetadata $metadata
67+ * @param DateTime $dateTime
6468 * @return Select
6569 */
66- private function getIdsSelect (int $ lastKnownId , FeedIndexMetadata $ metadata ): Select
70+ private function getIdsSelect (int $ lastKnownId , FeedIndexMetadata $ metadata, DateTime $ dateTime ): Select
6771 {
6872 $ connection = $ this ->resourceConnection ->getConnection ();
6973 $ tableName = $ this ->resourceConnection ->getTableName ($ metadata ->getSourceTableName ());
7074
7175 $ columnExpression = sprintf ('s.%s ' , $ metadata ->getSourceTableIdentityField ());
7276 $ whereClause = sprintf ('s.%s > ? ' , $ metadata ->getSourceTableIdentityField ());
7377
74- return $ connection ->select ()
78+ $ select = $ connection ->select ()
7579 ->from (
7680 ['s ' => $ tableName ],
7781 [
7882 $ metadata ->getFeedIdentity () => 's. ' . $ metadata ->getSourceTableField (),
7983 self ::IDENTITY_FIELD_NAME => 's. ' . $ metadata ->getSourceTableIdentityField ()
8084 ]
8185 )
82- ->where ($ whereClause , $ lastKnownId )
86+ ->where ($ whereClause , $ lastKnownId );
87+
88+ if ($ metadata ->getFullReIndexSecondsLimit () != 0 ) {
89+ $ select ->where (sprintf (
90+ "s.%s >= DATE_SUB(STR_TO_DATE('%s', '%%Y-%%m-%%d %%H:%%i:%%s'), INTERVAL %d SECOND) " ,
91+ $ metadata ->getSourceTableFieldOnFullReIndexLimit (),
92+ $ dateTime ->format ('Y-m-d H:i:s ' ),
93+ $ metadata ->getFullReIndexSecondsLimit ()
94+ ));
95+ }
96+
97+ return $ select
8398 ->order ($ columnExpression )
8499 ->limit ($ metadata ->getBatchSize ());
85100 }
0 commit comments