Роман Ильин · 12 сентября 2017, 23:09 Сниппет для удаления старых версий: <?php /** * versionCleanX * * @author Scott Pronych, September 27, 2013 * * DESCRIPTION * * For use with VersionX to delete old content * * PROPERTIES: * * &contentType - can be resource, chunk, plugin, snippet, template, or templatevar * &maxVersions - integer value for max number of versions you would like to keep * * USAGE: * * [[!versionCleanX? &contentType=`resource` &maxVersions=`10`]] * */ $cx_type = $modx->getOption('contentType', $scriptProperties, 'resource'); $cx_max = (int) $modx->getOption('maxVersions', $scriptProperties, 5); $GLOBALS['count'] = 1; $GLOBALS['total'] = 0; $GLOBALS['deleted'] = 0; $GLOBALS['page_total'] = 0; $GLOBALS['page_deleted'] = 0; $GLOBALS['page_name'] = ''; $GLOBALS['prev_content_id'] = 0; $GLOBALS['prev_version_id'] = 0; switch ($cx_type) { case 'chunk': $name = 'name'; break; case 'plugin': $name = 'name'; break; case 'snippet': $name = 'name'; break; case 'template': $name = 'templatename'; break; case 'templatevar': $name = 'name'; break; default: $name = 'title'; $cx_type = 'resource'; } $GLOBALS['db_name'] = 'modx_versionx_' . $cx_type; function delete_row ($id) { global $modx; $query = "DELETE FROM `" . $GLOBALS['db_name'] . "` WHERE version_id = '" . $id . "'"; $result = $modx->query($query); if (!is_object($result)) return false; else { $GLOBALS['deleted']++; $GLOBALS['page_deleted']++; $GLOBALS['page_total']++; $GLOBALS['total']++; $GLOBALS['count']++; return true; } } function log_row () { $GLOBALS['data'] .= '<tr><td>' . $GLOBALS['page_name'] . '</td><td>' . $GLOBALS['page_total'] . '</td><td>' . $GLOBALS['page_deleted'] . "</td></tr>\n"; $GLOBALS['page_deleted'] = 0; $GLOBALS['page_total'] = 1; $GLOBALS['count'] = 1; } $query = "SELECT version_id, content_id, " . $name . " AS page_title FROM `" . $GLOBALS['db_name'] . "` ORDER BY content_id ASC, version_id DESC"; $GLOBALS['data'] = ''; $output = 'An error occurred: '; $versionx = $modx->query($query); if (!is_object($versionx)) { return $output . 'query error ' . print_r($modx->errorInfo(), true); } else { while($row = $versionx->fetch(PDO::FETCH_ASSOC)) { // New content_id so reset if ($prev_content_id == 0) { $prev_content_id = $row['content_id']; $prev_version_id = $row['version_id']; $GLOBALS['total']++; $GLOBALS['page_total']++; $GLOBALS['count']++; $GLOBALS['page_name'] = $row['page_title']; } elseif ($prev_content_id != $row['content_id']) { if ($GLOBALS['count'] > $cx_max) { if (!delete_row($prev_version_id)) return $output . 'deleting row for ' . $GLOBALS['page_name'] . ' Row: ' . $prev_content_id . ' ' . print_r($modx->errorInfo(), true); $GLOBALS['page_total']--; } else { $GLOBALS['total']++; $GLOBALS['count']++; } log_row(); $prev_content_id = $row['content_id']; $prev_version_id = $row['version_id']; $GLOBALS['page_name'] = $row['page_title']; } // Content count is over the max so delete previous row elseif ($GLOBALS['count'] > $cx_max) { delete_row($prev_version_id); $prev_content_id = $row['content_id']; $prev_version_id = $row['version_id']; } else { $GLOBALS['count']++; $GLOBALS['page_total']++; $GLOBALS['total']++; $prev_content_id = $row['content_id']; $prev_version_id = $row['version_id']; } } log_row(); if ($GLOBALS['data'] != '') { $output = '<h3>VersionX Cleanup for ' . $GLOBALS['db_name'] . '</h3> <p>Total records: <strong>' . $GLOBALS['total'] . '</strong> Total deleted: <strong>' . $GLOBALS['deleted'] . '</strong></p> <table class="table table-striped"> <thead> <tr> <th>Page name</th> <th>Total found</th> <th>Deleted</th> </tr> </thead> <tbody> ' . $GLOBALS['data'] . '</tbody></table> '; } else $output = 'Error: no data found.'; } $query = "OPTIMIZE TABLE `" . $GLOBALS['db_name'] . "`"; $versionx = $modx->query($query); if (!is_object($versionx)) { $output = 'Optimize error ' . print_r($modx->errorInfo(), true) . $output; } return $output; Вызывать так: [[!versionCleanX? &contentType=`resource` &maxVersions=`10`]] Вопросы / VersionX переполнил базу данных 8 +2 13
[videoGallery] Видео галерея YouTube, Vimeo Невозможно установить пакет с подписью: videogallery-1.4.0-beta Ошибка установки Error в /core/packages/videogallery-1.4.0-beta/modCategory/7fc931a7772edc9752c16e9c41eb5e52.reso...
mxBoard: канбан-доска для команд, людей и ИИ-агентов в MODX 3 Привет, добавил пользователя в группу mxBoard(4), создал токен. Добавляю все в postman пишет: rest: { «success»: false, «message»: «Недействительный токен.», «data...
Релиз miniShop2 ver. 4.4.1 & 4.4.2 Подскажите пожалуйста, может я что-то не знаю или упустил. Но есть ли решение по глюку с radio? Указываешь свое radio c одинаковым name и в результате при переключении получаешь вс...
Плагин EnvBadge: визуальный индикатор окружения в админке MODX3 Расскажите пожалуйста как вы настраиваете сайт на MODX 3 чтобы был dev, prod, stage. Можете описать workflow? Допустим у меня 80% — это магазины, там клиенты, продажи, все онлай...
MaxNotify Обновление компонента 1.3.0-pl (22.07.2026) — добавлено автоматическое получение полей через msOrder->toArray(); — массивы и объекты безопасно пропускаются; — стандартные...
MyFavorites MyFavorites — 3.0.0-beta Первая версия для MODX Revolution 3.x — компонент полностью переписан с нуля (PHP >= 8.4, namespaced-ядро MODX 3, PSR-4, сервис-ориентированная архит...
Вызывать так: