From ecbb1a325fc769d9481db900383bf46c2b37c22b Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Tue, 11 Feb 2020 23:35:55 +0300 Subject: [PATCH] + `\ddTools::updateDocument`: Cache of the updated docs and their parents will be cleared. --- modx.ddtools.class.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/modx.ddtools.class.php b/modx.ddtools.class.php index cfc8971..7ad7f92 100644 --- a/modx.ddtools.class.php +++ b/modx.ddtools.class.php @@ -1370,9 +1370,9 @@ public static function createDocument( /** * updateDocument - * @version 1.3.3 (2020-02-10) + * @version 1.4 (2020-02-11) * - * @desc Update a document. + * @desc Update document(s). Cache of the updated docs and their parents will be cleared. * * @note $docId and/or $where are required. * @@ -1438,6 +1438,11 @@ public static function updateDocument( ); if (self::$modx->db->getRecordCount($docIdsToUpdate_dbRes)){ + $docIdsToUpdate = []; + while ($doc = self::$modx->db->getRow($docIdsToUpdate_dbRes)){ + $docIdsToUpdate[] = $doc['id']; + } + //Разбиваем на поля документа и TV $docData = self::prepareDocData([ 'data' => $docData, @@ -1459,7 +1464,10 @@ public static function updateDocument( //Если есть хоть одна TV if (count($docData->tvsAdditionalData) > 0){ //Обновляем TV всех найденых документов - while ($doc = self::$modx->db->getRow($docIdsToUpdate_dbRes)){ + foreach ( + $docIdsToUpdate as + $docId + ){ //Перебираем массив существующих TV foreach ( $docData->tvsAdditionalData as @@ -1480,7 +1488,7 @@ public static function updateDocument( self::$modx->db->update( '`value` = "' . $docData->tvsData[$tvName] . '"', self::$tables['site_tmplvar_contentvalues'], - '`tmplvarid` = ' . $tvData['id'] . ' AND `contentid` = ' . $doc['id'] + '`tmplvarid` = ' . $tvData['id'] . ' AND `contentid` = ' . $docId ); //Проверяем сколько строк нашлось при обновлении @@ -1510,7 +1518,7 @@ public static function updateDocument( [ 'value' => $docData->tvsData[$tvName], 'tmplvarid' => $tvData['id'], - 'contentid' => $doc['id'] + 'contentid' => $docId ], self::$tables['site_tmplvar_contentvalues'] ); @@ -1519,6 +1527,11 @@ public static function updateDocument( } } + //Clear cache of updated docs + self::clearCache([ + 'docIds' => $docIdsToUpdate + ]); + return true; }