Extension breaks dashboard

Discussion in 'Extensions' started by assuncao, Mar 7, 2018.

  1. assuncao

    assuncao Member

    Joined:
    Aug 17, 2016
    Messages:
    55
    Likes Received:
    7
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    Hi,

    I would like to know if does anyone know how to solve the issue that I have in this extension that I'm developing:

    PHP:
    <?php defined('MW_PATH') || exit('No direct script access allowed');

    class 
    DashFasterExt extends ExtensionInit
    {

        public 
    $name 'Dashboard';
        public 
    $description 'Makes Dashboard faster';
        public 
    $version '1.0';
        public 
    $author 'Author';
        public 
    $website 'https://www.example.com.br';
        public 
    $email 'example@example.com';
        public 
    $allowedApps = array('backend');
        public 
    $notAllowedApps = array();
        protected 
    $_canBeDeleted true;
        protected 
    $_canBeDisabled true;

        public function 
    run()
        {

            
    Yii::app()->hooks->addFilter('backend_dashboard_glance_stats_list', function(array $items = array(), $controller){

                
    $cacheKey md5('backend.dashboard.glanceStats');
                
    $cache    Yii::app()->cache;

                if ((
    $items $cache->get($cacheKey))) {
                    return 
    $items;
                }

                
    $items = array(
                    array(
                        
    'count'     => Yii::app()->format->formatNumber(Customer::model()->count()),
                        
    'heading'   => Yii::t('dashboard''Customers'),
                        
    'icon'      => IconHelper::make('ion-person-add'),
                        
    'url'       => $this->createUrl('customers/index'),
                    ),
                    array(
                        
    'count'     => Yii::app()->format->formatNumber(Campaign::model()->count()),
                        
    'heading'   => Yii::t('dashboard''Campaigns'),
                        
    'icon'      => IconHelper::make('ion-ios-email-outline'),
                        
    'url'       => $this->createUrl('campaigns/index'),
                    )
                    
    /*,
                    array(
                        'count'     => Yii::app()->format->formatNumber(Lists::model()->count()),
                        'heading'   => Yii::t('dashboard', 'Lists'),
                        'icon'      => IconHelper::make('ion ion-clipboard'),
                        'url'       => $this->createUrl('lists/index'),
                    ),
                    */
                    
    ,
                    array(
                        
    'count'     => Yii::app()->format->formatNumber(ListSubscriber::model()->count()),
                        
    'heading'   => Yii::t('dashboard''Subscribers'),
                        
    'icon'      => IconHelper::make('ion-ios-people'),
                        
    'url'       => 'javascript:;',
                    ),
                    array(
                        
    'count'     => Yii::app()->format->formatNumber(ListSegment::model()->count()),
                        
    'heading'   => Yii::t('dashboard''Segments'),
                        
    'icon'      => IconHelper::make('ion-gear-b'),
                        
    'url'       => 'javascript:;',
                    ),
                    array(
                        
    'count'     => Yii::app()->format->formatNumber(DeliveryServer::model()->count()),
                        
    'heading'   => Yii::t('dashboard''Delivery servers'),
                        
    'icon'      => IconHelper::make('ion-paper-airplane'),
                        
    'url'       => $this->createUrl('delivery_servers/index'),
                    )
                  
                );

                
    $cache->set($cacheKey$items600);

                return 
    $items;

            });

        }
     
    }
    Once it get activated, the dashboard stop working. I just would like to make this extension to stop counting the subscribers, I think it is making the backend slow. Currently there are about 44 million subscribers.

    Thanks
     
    Last edited: Mar 7, 2018
  2. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,254
    Likes Received:
    2,382
  3. assuncao

    assuncao Member

    Joined:
    Aug 17, 2016
    Messages:
    55
    Likes Received:
    7
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    Thanks for answer me back. Just to know if I got it in the right way, if I add my public IP to "MW_DEVELOPERS_IPS", will the debug mode be available only for me? I'm afraid my customers see it. It is a production env.
     
    frm.mwz likes this.
  4. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,254
    Likes Received:
    2,382
    This is correct, that's the exact point for that constant ;)
     
  5. assuncao

    assuncao Member

    Joined:
    Aug 17, 2016
    Messages:
    55
    Likes Received:
    7
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    That's absolutely amazing this feature. Well, debug mode made my life easier. The error wasn't hard to get fixed, there was just $this-> as result from my copy and paste. I replaced by Yii::app()-> and "voilĂ "! Thanks again!
     
    twisted1919 likes this.
  6. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,254
    Likes Received:
    2,382
    You always should code with debug mode enabled ;)
     
    assuncao likes this.

Share This Page