Block with custom code preventing any edition on the site

Permalink
Hello,

I have added in an HTML block in one of my global areas and it turns out that the script in the content is causing issue on the page. It generates no error but it no longer to update any page as the top bar with is no longer visible (white) and all the areas are not accessible for edition.

I tried to go from the "Stack & Global Areas" menu as well, it worked for all blocks except the one causing the issue, the "Clear Global Area" button does nothing and the "Version History" button fails to render the history.

I am currently stuck I could not find where this is stored neither in the DB nor on the server. Any help to get rid of this broken block would be more than welcome !

Thanks

 
mnakalay replied on at Permalink Reply
mnakalay
Hello,
this easiest way would be to go to the block itself and disabled the part that outputs the code to the page so you can delete it.

Look for the file concrete\blocks\html\view.php or the same one in the updates folder if you have updated concrete5 and comment out this line:
<?php echo $content; ?>

Or even better replace it with
<?php echo "I'm an HTML block"; ?>

So you can still see it.

The delete the block from your page and save.

Don"t forget to change your block's view file back the way it's supposed to be afterward.
meglasson replied on at Permalink Reply
Hello,

I tried without success with my faulty block (the workaround worked fine for the other blocks of the same type, so it was a very good suggestion, thanks!).

For my particular block, I tried also to do the same trick with the type "Content" in case I had used that type of block, same issue. Seems I have a bigger problem as I do not recall what type of block I used... Anybody knows how I could find what block is linked to "Footer Lvl2 Col5" Global Area ?

Thanks
Marie-Eve
mnakalay replied on at Permalink Reply
mnakalay
try this.
Open your file application\bootstrap\app.php and add this code to it
Events::addListener('on_start', function($event) {
    $page = \Page::getCurrentPage();
    $blocks = $page->getBlocks("Footer Lvl2 Col5");
    if (count($blocks)) {
        foreach ($blocks as $block) {
            \Log::addEntry("block with handle " . $block->getBlockTypeHandle());
        }
    }
});

Then open a page which uses the global area you're trying to check. Once that's done go to the Logs page in your dashboard and you should see all handles for all blocks in that area.
meglasson replied on at Permalink Reply
Hello,

i've added the code to the page as suggested, but it throws an error in the log:
Exception Occurred: .../application/bootstrap/app.php:5 Call to a member function getBlocks() on null (0)

I tried to see what was wrong but I am not familiar enough with the API to identify the problem. Any clue ?

Thanks !
mnakalay replied on at Permalink Reply
mnakalay
Try this. replace this line
$page = \Page::getCurrentPage();

With
$page = \Page::getByID(xxx);

Where you replace xxx with the ID of a page that contains the area. For instance the homepage has an ID of 1.
meglasson replied on at Permalink Reply
Hello,

No more error, but my log stays empty... But, as in the meantime I found in the database the faulty code (a missing < in a script) I no longer need to identify the faulty block.

Thank you so much for having tried to help ! It is much appreciated.
JohntheFish replied on at Permalink Reply
JohntheFish
If you are using html blocks to add snippets of script, there are better (ie much safer) ways to do it.

With an HTML block, use my Safe HTML block template
https://www.concrete5.org/marketplace/addons/safe-html...

Or use @mesuva's Script Output block https://www.concrete5.org/marketplace/addons/script-output/...