Upgrade to 2.5.6/2.5.7: Cannot declare class Asset, because the name is already in use


#1

I just upgraded my site to 2.5.7 from 2.5.5, and it results in a blank site, with the browser saying this site is not working. I don’t even get a whoops page.

Anyone else having any trouble?


If check and fallback in Kirby Meta plugin
#2

Did you check your PHP error log?


#3

Ok there is this error in the log…

[Tue Nov 14 12:49:58.997497 2017] [php7:notice] [pid 7292] [client 192.168.10.1:49424] PHP Fatal error:  Cannot declare class Asset, because the name is already in use in /home/vagrant/hashandsalt/public/kirby/branches/multilang.php on line 0
[Tue Nov 14 12:49:58.997521 2017] [php7:notice] [pid 7292] [client 192.168.10.1:49424] PHP Stack trace:
[Tue Nov 14 12:49:58.997526 2017] [php7:notice] [pid 7292] [client 192.168.10.1:49424] PHP   1. {main}() /home/vagrant/hashandsalt/public/index.php:0
[Tue Nov 14 12:49:58.997529 2017] [php7:notice] [pid 7292] [client 192.168.10.1:49424] PHP   2. Kirby->launch() /home/vagrant/hashandsalt/public/index.php:16
[Tue Nov 14 12:49:58.997539 2017] [php7:notice] [pid 7292] [client 192.168.10.1:49424] PHP   3. Kirby->site() /home/vagrant/hashandsalt/public/kirby/kirby.php:695

Im running it on the Homestead vagrant box. I also emptied the plugins folder, but issue persists.


#4

I found this issue on GitHub: https://github.com/getkirby/kirby/issues/606. Is there anything in your config?


#5

I do have this:

c::set('languages', array(
  array(
    'code'    => 'en',
    'name'    => 'English',
    'default' => true,
    'locale'  => 'en_GB',
    'url'     => '/',
  )
));

Removing it makes the site work, sort of, but obviously all my content is now wrong because they are in the form of pagename.en.txt. but at least i am getting a whoops now.


#6

Hm, the language definition shouldn’t be causing this, though, just calling Kirby in the config


#7

I am certainly not doing this.


#8

Do you use any plugins?


#9

Yes, however, I did empty the plugins folder and the issue persisted. I have the following plugins, some of which have config settings:

autofocus
autoid
cachebuster
focus
headlineaccordion
images
js-component.php
kirby-html-minifier
meta-tags
piwik
uniform
xml-sitemap


#10

Could you please post your full config.php (you may remove the license and other private information)?


#11

And if you have more than one config file, then all of them.


#12

Sure, here you go…i have 3, however the local one is the only one I know has an issue, i have not tried on live or staging.

local config

c::set('ka.piwik.url', 'XXX');
c::set('ka.piwik.id', 1);
c::set('ka.piwik.tracking', true);
c::set('ka.piwik.trackingIfLoggedIn', true);
c::set('ka.piwik.widget', true);
c::set('ka.piwik.language', 'en');
c::set('ka.piwik.apitoken', 'XXX');

c::set('cachebuster', false);
c::set('livedomain', 'hashandsalt.dev');

c::set('auto.js.filename', '{name}.js');

c::set('fbpageid', 'XXX');

c::set('license', 'XXX');

c::set('languages', array(
  array(
    'code'    => 'en',
    'name'    => 'English',
    'default' => true,
    'locale'  => 'en_GB',
    'url'     => '/',
  )
));

c::set('debug',true);
c::set('cache',false);
c::set('panel.install', true);


// SEO Settings
c::set('meta-tags.default', [
    'title' => function($page) {
        return $page->isHomePage()
                ? site()->seotitle()
                : $page->seotitle().' | '.site()->seotitle();
    },
    'meta' => [
        'description' => function($page) {
            return $page->isHomePage()
            ? site()->seometa()
            : $page->seometa();
        },
        'keywords' => function($page) {
            return $page->isHomePage()
            ? site()->seokeywords()
            : $page->seokeywords();
        },
        'robots' => 'index,follow,noodp',
    ],
    'link' => [
        'canonical' => function($page) { return $page->url(); }
    ],
    'og' => [
        'title' => function($page) {
            return $page->isHomePage()
            ? site()->seotitle()
            : $page->seotitle().' | '.site()->seotitle();
        },
        'image' => function($page) {
          return $page->isHomePage()
          ? site()->shareimage()->toFile()->focusCrop(1200,630)->url()
          : $page->shareimage()->toFile()->focusCrop(1200,630)->url();
        },
        'type' => 'website',
        'site_name' => site()->seotitle(),
        'url' => function($page) { return $page->url(); },
        'description' => function($page) {
            return $page->isHomePage()
            ? site()->seometa()
            : $page->seometa();
        },
    ],
    'twitter' => [
        'title' => function($page) {
            return $page->isHomePage()
            ? site()->seotitle()
            : $page->seotitle().' | '.site()->seotitle();
        },
        'card' => 'summary',
        'site' => site()->twitterusername(),
        'creator' => site()->twitterhandle(),
        'image' => function($page) {
          return $page->isHomePage()
          ? site()->shareimage()->toFile()->focusCrop(800,400)->url()
          : $page->shareimage()->toFile()->focusCrop(800,400)->url();
        },
        'url' => function($page) { return $page->url(); },
        'description' => function($page) {
            return $page->isHomePage()
            ? site()->seometa()
            : $page->seometa();
        },
    ]
]);

c::set('meta-tags.templates', [

'workarticle' => [
  'meta' => [
      'robots' => 'index,follow,noodp'
  ],
  'og' => [
      'type' => 'article',
  ],
  'twitter' => [
      'card' => 'summary_large_image',
      'image' => function($page) {
        return $page->shareimage()->toFile()->focusCrop(800,400)->url();
      },
  ]
],

]);

live config:

c::set('livedomain', 'hashandsalt.com');
c::set('auto.js.filename', '{name}.min.js');
c::set('debug',false);
c::set('cache',false);
c::set('ssl',true);
c::set('panel.install', false);
c::set('cachebuster', true);

Staging…

c::set('livedomain', 'dev.hashandsalt.com');
c::set('auto.js.filename', '{name}.js');
c::set('debug',false);
c::set('cache',false);
c::set('ssl',true);
c::set('panel.install', false);
c::set('cachebuster', false);

#13

It’s those setting causing this. When I put that in a langkit, I get the same error.


#14

Confirmed, if i take those out completely, the site works. What you mean by langkit? Is there a syntax error? I followed the docs for the meta tags plugin, and it works fine with 2.5.5.

Is the issue me or the plugin? :slight_smile:


#15

Seems to be the calls to site() causing this issue.


#16

Is there an alternative way to get the same result?


#17

Replace site() with $site. And always wrap it in a function:

c::set('meta-tags.default', [
    'title' => function($page) {
        return $page->isHomePage()
                ? $site->seotitle()
                : $page->seotitle().' | '. $site->seotitle();
    },
    'meta' => [
        'description' => function($page) {
            return $page->isHomePage()
            ? $site->seometa()
            : $page->seometa();
        },
        'keywords' => function($page) {
            return $page->isHomePage()
            ? $site->seokeywords()
            : $page->seokeywords();
        },
        'robots' => 'index,follow,noodp',
    ],
    'link' => [
        'canonical' => function($page) { return $page->url(); }
    ],
    'og' => [
        'title' => function($page) {
            return $page->isHomePage()
            ? $site->seotitle()
            : $page->seotitle().' | '. $site->seotitle();
        },
        'image' => function($page) {
          return $page->isHomePage()
          ? $site->shareimage()->toFile()->focusCrop(1200,630)->url()
          : $page->shareimage()->toFile()->focusCrop(1200,630)->url();
        },
        'type' => 'website',
        'site_name' => function($page) {
            return $site->seotitle();
        },
        'url' => function($page) { return $page->url(); },
        'description' => function($page) {
            return $page->isHomePage()
            ? $site->seometa()
            : $page->seometa();
        },
    ],
    'twitter' => [
        'title' => function($page) {
            return $page->isHomePage()
            ? $site->seotitle()
            : $page->seotitle().' | '. $site->seotitle();
        },
        'card' => 'summary',
        'site' => function($page) {
            return $site->twitterusername();
        },
        'creator' => function($page) {
            return $site->twitterhandle();
        },
        'image' => function($page) {
          return $page->isHomePage()
          ? $site->shareimage()->toFile()->focusCrop(800,400)->url()
          : $page->shareimage()->toFile()->focusCrop(800,400)->url();
        },
        'url' => function($page) { return $page->url(); },
        'description' => function($page) {
            return $page->isHomePage()
            ? $site->seometa()
            : $page->seometa();
        },
    ]
]);

#18

That doesnt fly, I tried that when i first set it up months ago, and just tried again. Issue persists.


#19

What exactly does not work?


#20

Swapping site() for $site I get a whoops… Undefined variable: site.

If i use the code you posted above, I still get a whoops, same error.