{"id":857,"date":"2012-06-01T10:50:58","date_gmt":"2012-06-01T10:50:58","guid":{"rendered":"http:\/\/blog.soton.ac.uk\/webteam\/?p=857"},"modified":"2012-06-01T10:51:09","modified_gmt":"2012-06-01T10:51:09","slug":"recovering-from-broken-php-code-in-a-php-code-block-in-drupal","status":"publish","type":"post","link":"https:\/\/blog.soton.ac.uk\/webteam\/2012\/06\/01\/recovering-from-broken-php-code-in-a-php-code-block-in-drupal\/","title":{"rendered":"Recovering from broken php code in a &#8220;PHP Code&#8221; block in Drupal 7"},"content":{"rendered":"<p>I love to live a little dangerously, and we allow our research group webmasters to put custom php code in their Drupal sites. This lets them do nice things like have blocks with &#8220;latest 3 publications&#8221; or &#8220;next seminar&#8221;. I keep meaning to write standard code for these but there&#8217;s millions of things on the TODO list as usual.<\/p>\n<p>Anyhow, the webmaster for a research group put a typo in the PHP code for a block that displayed on every page on his site. This meant he couldn&#8217;t get into the site at all as no pages could render (we just saw a white page with a scrap of text generated before the php error)<\/p>\n<p>I couldn&#8217;t find a blog post about how to recover from the situation so I figured I should write one.<\/p>\n<h2>Solution:<\/h2>\n<p>Go into the MySQL database for the site, and issue the following command:<\/p>\n<pre>mysql&gt; update block_custom set format='full_html' where format='php_code' ;<\/pre>\n<p>Admittedly it&#8217;s a bit of a blunt instrument and stops php working in all blocks, to be a bit more subtle you could do.<\/p>\n<pre>mysql&gt; select bid,info,format from block_custom ;\r\n+-----+-------------------+---------------+\r\n| bid | info\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | format\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |\r\n+-----+-------------------+---------------+\r\n|\u00a0\u00a0 2 | Student Quotation | full_html\u00a0\u00a0\u00a0\u00a0 |\r\n|\u00a0\u00a0 3 | Footer Links\u00a0\u00a0\u00a0\u00a0\u00a0 | full_html\u00a0\u00a0\u00a0\u00a0 |\r\n|\u00a0\u00a0 4 | Latest News\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | php_code\u00a0\u00a0\u00a0\u00a0\u00a0 |\r\n|\u00a0\u00a0 5 | Seminars\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | php_code\u00a0\u00a0\u00a0\u00a0\u00a0 |\r\n|\u00a0\u00a0 6 | Demo HVLab Link\u00a0\u00a0 | filtered_html |\r\n|\u00a0\u00a0 7 | LeftBar\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | filtered_html |\r\n|\u00a0\u00a0 8 | Lower Left\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | php_code\u00a0\u00a0\u00a0\u00a0\u00a0 |\r\n|\u00a0\u00a0 9 | Featured News\u00a0\u00a0\u00a0\u00a0 | php_code\u00a0\u00a0\u00a0\u00a0\u00a0 |\r\n|\u00a0 10 | Featured Project\u00a0 | php_code\u00a0\u00a0\u00a0\u00a0\u00a0 |\r\n|\u00a0 11 | t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | filtered_html |\r\n+-----+-------------------+---------------+\r\n10 rows in set (0.00 sec)<\/pre>\n<pre>mysql&gt; update block_custom set format='full_html' where bid=6;<\/pre>\n<p>Where bid is the number of the block you want to reset.<\/p>\n<h2>Prevention:<\/h2>\n<p>To avoid getting into this situation is quite easy. It only happens if the broken block is on all pages, so make a page for testing new blocks and limit the PHP block to only show on that page while you&#8217;re working on it. If that page breaks you will still be able to go through the homepage to get to the admin interface.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I love to live a little dangerously, and we allow our research group webmasters to put custom php code in their Drupal sites. This lets them do nice things like have blocks with &#8220;latest 3 publications&#8221; or &#8220;next seminar&#8221;. I keep meaning to write standard code for these but there&#8217;s millions of things on the [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[4231,74],"tags":[],"class_list":["post-857","post","type-post","status-publish","format-standard","hentry","category-drupal","category-tips"],"_links":{"self":[{"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/posts\/857","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/comments?post=857"}],"version-history":[{"count":2,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/posts\/857\/revisions"}],"predecessor-version":[{"id":859,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/posts\/857\/revisions\/859"}],"wp:attachment":[{"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/media?parent=857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/categories?post=857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/tags?post=857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}