webvimark / user-management

154 stars 163 forks source link

Refresh routes - TypeError #163

Open chococola opened 7 years ago

chococola commented 7 years ago

Hello! I had a problem. And I do not know exactly how to fix it.

When I click on the button "Refresh routes" in the edit menu "Routes", I get this error "Argument 1 passed to yii\di\Container::invoke() must be callable, array given, called in /var/www/site1/vendor/yiisoft/yii2/BaseYii.php on line 346".

I would really appreciate if you can help solve this problem. Thank you!

01 02

dtmonterrey commented 7 years ago

I never had that error, can you give the full error stack?

chococola commented 7 years ago

@dtmonterrey , Thx for reply... I forgot to specify what use, "advanced template"

chococola commented 7 years ago
Exception
TypeError

Argument 1 passed to yii\di\Container::invoke() must be callable, array given, called in /var/www/webpath/vendor/yiisoft/yii2/BaseYii.php on line 346
1. in /var/www/webpath/vendor/yiisoft/yii2/di/Container.php at line 491
482483484485486487488489490491492493494495496497498499500     *
     * @param callable $callback callable to be invoked.
     * @param array $params The array of parameters for the function.
     * This can be either a list of parameters, or an associative array representing named function parameters.
     * @return mixed the callback return value.
     * @throws InvalidConfigException if a dependency cannot be resolved or if a dependency cannot be fulfilled.
     * @throws NotInstantiableException If resolved to an abstract class or an interface (since 2.0.9)
     * @since 2.0.7
     */
    public function invoke(callable $callback, $params = [])
    {
        if (is_callable($callback)) {
            return call_user_func_array($callback, $this->resolveCallableDependencies($callback, $params));
        } else {
            return call_user_func_array($callback, $params);
        }
    }

    /**
2. in /var/www/webpath/vendor/yiisoft/yii2/BaseYii.php at line 346 – yii\di\Container::invoke(['gii', 'debug'], ['bootstrap', yii\web\Application])
3. in /var/www/webpath/vendor/yiisoft/yii2/base/Module.php at line 353 – yii\BaseYii::createObject(['gii', 'debug'], ['bootstrap', yii\web\Application])
4. in /var/www/webpath/vendor/webvimark/module-user-management/components/AuthHelper.php at line 266 – yii\base\Module::getModule('bootstrap')
260261262263264265266267268269270271272     * @param array            $result
     */
    private static function getRouteRecursive($module, &$result)
   {
       foreach ($module->getModules() as $id => $child)
       {
           if ( ($child = $module->getModule($id)) !== null )
           {
               self::getRouteRecursive($child, $result);
            }
        }
        /* @var $controller \yii\base\Controller */
        foreach ($module->controllerMap as $id => $value)
5. in /var/www/webpath/vendor/webvimark/module-user-management/components/AuthHelper.php at line 253 – webvimark\modules\UserManagement\components\AuthHelper::getRouteRecursive(yii\web\Application, ['/gridview/export/download', '/gridview/export/*', '/gridview/*'])
247248249250251252253254255256257258259    /**
     * @return array
     */
    public static function getRoutes()
    {
        $result = [];
        self::getRouteRecursive(Yii::$app, $result);

        return array_reverse(array_combine($result, $result));
    }

    /**
     * @param \yii\base\Module $module
6. in /var/www/webpath/vendor/webvimark/module-user-management/models/rbacDB/Route.php at line 120 – webvimark\modules\UserManagement\components\AuthHelper::getRoutes()
114115116117118119120121122123124125126     * and backend have they own set of routes.
     *
     * @param bool $deleteUnusedRoutes
     */
    public static function refreshRoutes($deleteUnusedRoutes = true)
    {
        $allRoutes = AuthHelper::getRoutes();

        $currentRoutes = ArrayHelper::map(Route::find()->asArray()->all(), 'name', 'name');

        $toAdd = array_diff(array_keys($allRoutes), array_keys($currentRoutes));

        foreach ($toAdd as $addItem)
7. in /var/www/webpath/vendor/webvimark/module-user-management/controllers/PermissionController.php at line 126 – webvimark\modules\UserManagement\models\rbacDB\Route::refreshRoutes(false)
120121122123124125126127128129130131132     * @param null   $deleteUnused
     *
     * @return \yii\web\Response
     */
    public function actionRefreshRoutes($id, $deleteUnused = null)
    {
        Route::refreshRoutes($deleteUnused !== null);

        return $this->redirect(['view', 'id'=>$id]);
    }

    /**
8. webvimark\modules\UserManagement\controllers\PermissionController::actionRefreshRoutes('work', null)
9. in /var/www/webpath/vendor/yiisoft/yii2/base/InlineAction.php at line 55 – call_user_func_array([webvimark\modules\UserManagement\controllers\PermissionController, 'actionRefreshRoutes'], ['work', null])
10. in /var/www/webpath/vendor/yiisoft/yii2/base/Controller.php at line 154 – yii\base\InlineAction::runWithParams(['id' => 'work'])
11. in /var/www/webpath/vendor/yiisoft/yii2/base/Module.php at line 454 – yii\base\Controller::runAction('refresh-routes', ['id' => 'work'])
12. in /var/www/webpath/vendor/yiisoft/yii2/web/Application.php at line 100 – yii\base\Module::runAction('user-management/permission/refre...', ['id' => 'work'])
13. in /var/www/webpath/vendor/yiisoft/yii2/base/Application.php at line 375 – yii\web\Application::handleRequest(yii\web\Request)
14. in /var/www/webpath/frontend/web/index.php at line 17 – yii\base\Application::run()
11121314151617    require(__DIR__ . '/../../common/config/main.php'),
    require(__DIR__ . '/../../common/config/main-local.php'),
    require(__DIR__ . '/../config/main.php'),
    require(__DIR__ . '/../config/main-local.php')
);

(new yii\web\Application($config))->run();
 $_GET = [
    'id' => 'work',
];

$_COOKIE = [
    'advanced-frontend' => '9hk6notit025nrbv60fitd8aj4',
    '_csrf-frontend' => 'ebf2c77667bcede67eab8b45d1203ff5bd60eaa368a2374eba147303185569eda:2:{i:0;s:14:"_csrf-frontend";i:1;s:32:"H0MG6cBP-9qaZrKJjMf0l-I1OjCCjXUp";}',
    '_csrf-web' => '4656dc090c831352c3e62f38f0c971e66bcc2653a264e749f94e92eed8195ea5a:2:{i:0;s:12:"_csrf-web";i:1;s:32:"7SoNt90QyAnlgZO05BWpZsuELg6e8HIm";}',
    'web-frontend' => 'qv9jvis6crsdkp8urmijdicn87',
    '_identity' => '2dcfcb8a04eeff876ecd3f1253f776f5af694edccf4af4373448c47af550d1c7a:2:{i:0;s:9:"_identity";i:1;s:46:"[1,"YH-5Tv5tidFNbaLREWsOb0uCKSx33P_S",2592000]";}',
];

$_SESSION = [
    '__flash' => [],
    '_um_last_attempt' => 1485263589,
    '_um_attempt_count' => 1,
    '__id' => 1,
    '__auth_last_update' => 1485102577,
    '__userRoles' => [
        'Admin',
    ],
    '__userPermissions' => [
        'assignRolesToUsers',
        'backend',
        'bindUserToIp',
        'changeOwnPassword',
        'changeUserPassword',
        'createUsers',
        'deleteUsers',
        'editUserEmail',
        'editUsers',
        'viewUserEmail',
        'viewUserRoles',
        'viewUsers',
        'viewVisitLog',
    ],
    '__userRoutes' => [
        '/*',
        '/*',
        '//*',
        '//*',
        '//controller',
        '//controller',
        '//crud',
        '//crud',
        '//extension',
        '//extension',
        '//form',
        '//form',
        '//index',
        '//index',
        '//model',
        '//model',
        '//module',
        '//module',
        '/asset/*',
        '/asset/*',
        '/asset/compress',
        '/asset/compress',
        '/asset/template',
        '/asset/template',
        '/cache/*',
        '/cache/*',
        '/cache/flush',
        '/cache/flush',
        '/cache/flush-all',
        '/cache/flush-all',
        '/cache/flush-schema',
        '/cache/flush-schema',
        '/cache/index',
        '/cache/index',
        '/controllers/*',
        '/controllers/*',
        '/controllers/OrdersController',
        '/controllers/OrdersController',
        '/fixture/*',
        '/fixture/*',
        '/fixture/load',
        '/fixture/load',
        '/fixture/unload',
        '/fixture/unload',
        '/gii/*',
        '/gii/*',
        '/gii/default/*',
        '/gii/default/*',
        '/gii/default/action',
        '/gii/default/action',
        '/gii/default/diff',
        '/gii/default/diff',
        '/gii/default/index',
        '/gii/default/index',
        '/gii/default/preview',
        '/gii/default/preview',
        '/gii/default/view',
        '/gii/default/view',
        '/help/*',
        '/help/*',
        '/help/index',
        '/help/index',
        '/message/*',
        '/message/*',
        '/message/config',
        '/message/config',
        '/message/config-template',
        '/message/config-template',
        '/message/extract',
        '/message/extract',
        '/migrate/*',
        '/migrate/*',
        '/migrate/create',
        '/migrate/create',
        '/migrate/down',
        '/migrate/down',
        '/migrate/history',
        '/migrate/history',
        '/migrate/mark',
        '/migrate/mark',
        '/migrate/new',
        '/migrate/new',
        '/migrate/redo',
        '/migrate/redo',
        '/migrate/to',
        '/migrate/to',
        '/migrate/up',
        '/migrate/up',
        '/serve/*',
        '/serve/*',
        '/serve/index',
        '/serve/index',
        '/user-management/*',
        '/user-management/*',
        '/user-management/*',
        '/user-management/auth/change-own-password',
        '/user-management/auth/change-own-password',
        '/user-management/auth/change-own-password',
        '/user-management/auth/change-own-password',
        '/user-management/user-permission/set',
        '/user-management/user-permission/set',
        '/user-management/user-permission/set',
        '/user-management/user-permission/set',
        '/user-management/user-permission/set-roles',
        '/user-management/user-permission/set-roles',
        '/user-management/user-permission/set-roles',
        '/user-management/user-permission/set-roles',
        '/user-management/user/bulk-activate',
        '/user-management/user/bulk-activate',
        '/user-management/user/bulk-activate',
        '/user-management/user/bulk-activate',
        '/user-management/user/bulk-deactivate',
        '/user-management/user/bulk-deactivate',
        '/user-management/user/bulk-deactivate',
        '/user-management/user/bulk-deactivate',
        '/user-management/user/bulk-delete',
        '/user-management/user/bulk-delete',
        '/user-management/user/bulk-delete',
        '/user-management/user/bulk-delete',
        '/user-management/user/change-password',
        '/user-management/user/change-password',
        '/user-management/user/change-password',
        '/user-management/user/change-password',
        '/user-management/user/create',
        '/user-management/user/create',
        '/user-management/user/create',
        '/user-management/user/create',
        '/user-management/user/delete',
        '/user-management/user/delete',
        '/user-management/user/delete',
        '/user-management/user/delete',
        '/user-management/user/grid-page-size',
        '/user-management/user/grid-page-size',
        '/user-management/user/grid-page-size',
        '/user-management/user/grid-page-size',
        '/user-management/user/index',
        '/user-management/user/index',
        '/user-management/user/index',
        '/user-management/user/index',
        '/user-management/user/update',
        '/user-management/user/update',
        '/user-management/user/update',
        '/user-management/user/update',
        '/user-management/user/view',
        '/user-management/user/view',
        '/user-management/user/view',
        '/user-management/user/view',
        '/views/*',
        '/views/*',
        '/views/orders/*',
        '/views/orders/*',
        '/views/site/*',
        '/views/site/*',
    ],
    '__visitorToken' => '588752e5dbbb9',
];
Yii Framework
2017-01-24, 16:13:19
dtmonterrey commented 7 years ago

Can you share your config/web.php

chococola commented 7 years ago

@dtmonterrey yup

<?php
$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/../../common/config/params-local.php'),
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php')
);

return [
    'language' => 'ru-RU',
    'sourceLanguage' => 'ru-RU',
    'timeZone' => 'Europe/Moscow',
    'id' => 'web-app',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'frontend\controllers',
    'components' => [
        'request' => [
            'csrfParam' => '_csrf-web',
        ],
       'user' => [
            'class' => 'webvimark\modules\UserManagement\components\UserConfig',
            'on afterLogin' => function($event) {
                    \webvimark\modules\UserManagement\models\UserVisitLog::newVisitor($event->identity->id);
             }
        ],
        'session' => [

            'name' => 'web-frontend',
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
      'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=localhost;dbname=base',
            'username' => 'root',
            'password' => 'pass',
            'charset' => 'utf8',
        ],   
     'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],

        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
            ],
        ],
        'i18n' => [
            'translations' => [
                    'app' => [
                        'class' => 'yii\i18n\PhpMessageSource',
                        'basePath' => '@app/messages',
                        'sourceLanguage' => 'ru',
                    ],
                    'kvgrid' => [
                        'class' => 'yii\i18n\PhpMessageSource',
                        'basePath' => '@app/messages',
                        'sourceLanguage' => 'ru',
                    ],

            ],
        ],

    ],
    'modules'=>[
        'gridview' => ['class' => 'kartik\grid\Module',
                 ],

        'bootstrap' => ['gii','debug'],
        'gii' => [
            'class' => \yii\gii\Module::className(),
            'allowedIPs' => ['ip'],
        ],
        'debug' => [
            'class' => 'yii\debug\Module',
            'allowedIPs' => ['ip'],
        ],
    'user-management' => [
        'class' => 'webvimark\modules\UserManagement\UserManagementModule',
        'on beforeAction'=>function(yii\base\ActionEvent $event) {
                if ( $event->action->uniqueId == 'user-management/auth/login' )
                {
                    $event->action->controller->layout = 'loginLayout.php';
                };
            },
    ],
],
    'params' => $params,
];
dtmonterrey commented 7 years ago

I can find the problem. I suggest you enable debug on the IDE and try to find the value of $modules and $id in /var/www/webpath/vendor/webvimark/module-user-management/components/AuthHelper.php at line 266

It must be something to do with your specific configuration.

chococola commented 7 years ago

@dtmonterrey , Many thanks for the tip! error was this bootstrap module, i add if($id!='bootstrap') in in /var/www/webpath/vendor/webvimark/module-user-management/components/AuthHelper.php in function getRouteRecursive

foreach ($module->getModules() as $id => $child)
        {

            if($id!='bootstrap')
                if ( ($child = $module->getModule($id)) !== null )
                {
                    self::getRouteRecursive($child, $result);

                }

        }

maybe this fix is stupid, but "Refresh routes " works!

dtmonterrey commented 7 years ago

That's odd... I noticed that you have 'bootstrap' as a module in your web.php. Why did you put it there? There's a 'bootstrap' param configured in line 15! Maybe @webvimark can give a better tip