Skip to content

Commit

Permalink
+ \ddTools::updateDocument: Cache of the updated docs and their par…
Browse files Browse the repository at this point in the history
…ents will be cleared.
  • Loading branch information
Ronef committed Feb 11, 2020
1 parent 412e850 commit ecbb1a3
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions modx.ddtools.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
);

//Проверяем сколько строк нашлось при обновлении
Expand Down Expand Up @@ -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']
);
Expand All @@ -1519,6 +1527,11 @@ public static function updateDocument(
}
}

//Clear cache of updated docs
self::clearCache([
'docIds' => $docIdsToUpdate
]);

return true;
}

Expand Down

0 comments on commit ecbb1a3

Please sign in to comment.