autoRedirector - Не сохраняется ресурс/контейнер
        Зависает на этапе сохранения — ресурс контейнер
MODX 2.8.6
php 8.2.11
В журнале Ошибок Modx Пусто!
Ошибки в консоли:
POST nko-expert.ru/connectors/index.php 500 (Internal Server Error)
Uncaught {message: 'JsonReader.read: Json object not found'}
Ошибка в логах сервера:
mod_fcgid: stderr: PHP Fatal error: Uncaught TypeError: array_merge(): Argument #2 must be of type array, xPDOIterator given in /var/www/vhosts/sites.ru/site.ru/httpdocs/core/cache/includes/elements/modplugin/22.include.cache.php:27, referer: site.ru/manager/?a=resource/update&id=527
Если снести плагин — сохраняется нормально!
Проверял на разных хостингах!
Работает на php 7.4.33
Начиная с версии php 8.0.30 Не работает!
    
    
                                                                                
            MODX 2.8.6
php 8.2.11
В журнале Ошибок Modx Пусто!
Ошибки в консоли:
POST nko-expert.ru/connectors/index.php 500 (Internal Server Error)
Uncaught {message: 'JsonReader.read: Json object not found'}
Ошибка в логах сервера:
mod_fcgid: stderr: PHP Fatal error: Uncaught TypeError: array_merge(): Argument #2 must be of type array, xPDOIterator given in /var/www/vhosts/sites.ru/site.ru/httpdocs/core/cache/includes/elements/modplugin/22.include.cache.php:27, referer: site.ru/manager/?a=resource/update&id=527
Если снести плагин — сохраняется нормально!
Проверял на разных хостингах!
Работает на php 7.4.33
Начиная с версии php 8.0.30 Не работает!
Комментарии: 8
                там в плагине ошибка
                    if($child_ids = $modx->getChildIds($resource->id,50,array('context' => $resource->context_key))){
            $resources = array_merge($resources, $modx->getIterator('modResource',array("id:IN" => $child_ids)));
        }версия php не причем            
                попробуйте заменить на этот плагин. там добавлен iterator_to_array для $modx->getIterator
                    <?php
$resourceEvents = array('OnBeforeDocFormSave', 'OnDocFormSave');
if (in_array($modx->event->name, $resourceEvents)) {
    foreach($scriptProperties as & $object){
        if(
            is_object($object)
            AND $object instanceof modResource
            AND $original = $modx->getObject('modResource', $object->id)
        ){
            $resource = $object;
            break;
        }
    }
}
switch ($modx->event->name) {
    case "OnManagerPageInit":
        $cssFile = MODX_ASSETS_URL.'components/autoredirector/css/mgr/main.css';
        $modx->regClientCSS($cssFile);
        break;
    case "OnBeforeDocFormSave":
        $resources = array(
            $resource,
            $modx->getObject('modResource',$resource->get('parent'))
        );
        if($child_ids = $modx->getChildIds($resource->id,50,array('context' => $resource->context_key))){
            $resources = array_merge($resources, iterator_to_array($modx->getIterator('modResource',array("id:IN" => $child_ids))));
        }
    case "OnResourceBeforeSort":
        if (empty($resources)) {
            foreach ($nodes as $node) {
                $resources[] = $modx->getObject('modResource',$node['id']);
            }
        }
        foreach ($resources as $res) {
            if (!empty($res)) {
                if (!$res->getProperty('old_uri','autoredirector')) {
                    $res->setProperty('old_uri',$res->get('uri'),'autoredirector');
                    $res->save();
                }
            }
        }
        break;
    case "OnDocFormSave":
        $resources = array(
            $resource,
            $modx->getObject('modResource',$resource->get('parent'))
        );
        if($child_ids = $modx->getChildIds($resource->id,50,array('context' => $resource->context_key))){
            $resources = array_merge($resources, iterator_to_array($modx->getIterator('modResource',array("id:IN" => $child_ids))));
        }
    case "OnResourceSort":
        if (empty($resources)) {
            foreach ($nodesAffected as $node) {
                $resources[] = $node;
            }
        }
        $modelPath = $modx->getOption('autoredirector_core_path',null,$modx->getOption('core_path').'components/autoredirector/').'model/';
        $modx->addPackage('autoredirector', $modelPath);
        $processorProps = array('processors_path' => $modx->getOption('autoredirector_core_path',null,$modx->getOption('core_path').'components/autoredirector/').'processors/');
        foreach ($resources as $res) {
            if (!empty($res)) {
                $old_uri = $res->getProperty('old_uri','autoredirector');
                $current_uri = $res->getAliasPath($res->get('alias'));
                if ($old_uri && $current_uri != $old_uri) {
                    $currentRuleQ = array('uri' => $current_uri);
                    if (!$modx->getOption('global_duplicate_uri_check')) {
                        $currentRuleQ['context_key'] = $res->get('context_key');
                    }
                    if ($currentRule = $modx->getObject('arRule', $currentRuleQ)) {
                        $response = $modx->runProcessor('mgr/item/remove', $currentRule->toArray(), $processorProps);
                        if ($response->isError()) {
                            $modx->log(modX::LOG_LEVEL_ERROR, 'AutoRedirector removing error. Message: '.$response->getMessage());
                        }
                    }
                    $arRule = array('uri' => $old_uri
                                    , 'context_key' => $res->get('context_key')
                                    , 'res_id' => $res->get('id'));
                    if (!$modx->getObject('arRule', $arRule)) {
                        $response = $modx->runProcessor('mgr/item/create', $arRule, $processorProps);
                        if ($response->isError()) {
                            $modx->log(modX::LOG_LEVEL_ERROR, 'AutoRedirector creating error. Message: '.$response->getMessage());
                        }
                    }
                }
                $res->setProperty('old_uri',$current_uri,'autoredirector');
                $res->save();
            }
        }
        break;
    case "OnPageNotFound":
        $uri = $_SERVER['REQUEST_URI'];
        $uri = str_replace($modx->getOption("site_url"),"",$uri);
        if (substr($uri, 0, 1) == "/") $uri = substr($uri, 1);
        $getparams = '';
        if (mb_strpos($uri,'?') !== FALSE) {
            $uri_split = explode('?',$uri);
            $uri = $uri_split[0];
            if(!$modx->getOption("autoredirector_clear_get",null, 0)) {
                $getparams = $uri_split[1];
            }
        }
        $uri = urldecode($uri);
        $RuleQ = array('uri' => $uri);
        if (!$modx->getOption('global_duplicate_uri_check')) {
            $RuleQ['context_key'] = $modx->context->get('key');
        }
        $modelPath = $modx->getOption('autoredirector_core_path',null,$modx->getOption('core_path').'components/autoredirector/').'model/';
        $modx->addPackage('autoredirector', $modelPath);
        if ($Rule = $modx->getObject('arRule', $RuleQ)) {
            if ($url = $modx->makeUrl($Rule->get('res_id'),'',$getparams)) {
                $modx->sendRedirect($url,array('responseCode' => 'HTTP/1.1 301 Moved Permanently'));
            }
        }
        break;
}            
                Спасибо! Всё работает            
                    
                Пожалуйста!            
                    
                Тоже благодарю за решение!            
                    
                Спасибо!            
                    
                Спасибо, помогло            
                    
                Спасибо большое )))            
                    
                            Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.