In order for Views to function properly the core Block Module needs to be enabled. While the entire site works properly without the Block Module which I assume is a performance boost, Views tries to update the Block database table. Independent of changing the block name, cache settings and machine name of blocks created in Views, Views functions correctly without the Block Module enabled.

I enabled the Block Module, changed the settings then disabled and uninstalled the Block Module. It maintained the settings change. I don't know if the cache settings are still respected.

This is an image of the error. http://imgur.com/6ZDLN

CommentFileSizeAuthor
#15 patch5.patch1.77 KBAdam S
#13 patch4.patch1.72 KBAdam S
#11 patch3.patch2.78 KBAdam S
#8 patch2.patch3.72 KBAdam S
#1 patch1.patch782 bytesAdam S

Comments

Adam S’s picture

StatusFileSize
new782 bytes

Since I only need to change the machine name of the View, I added a condition of the Block module existing to protect against trying to write to the block table. I figure the machine names will all be created by the time I upgrade or if the case is that I need the Block Module installed it will work just the same. Here is the patch.

merlinofchaos’s picture

Maybe the check should be inside the update_block_bid() function so that it's safer to call from other locations should that need to happen for some other reason.

Adam S’s picture

When changing Block name or Block caching, Views also tries to write to the block table. Should these options not appear when the Block module is disabled? Or, should they be struck through with a warning, perhaps, that the Block module has been disabled?

merlinofchaos’s picture

Should the entire block display be dependent upon block module? I mean, can you do anything with it without block module?

Adam S’s picture

I'm using the Context module with Blocks disabled. **ducks and hides

dawehner’s picture

Yeah it's indeed a plugin that block module is both api and ui and api's in drupal are hooks which are indepedent from modules.

merlinofchaos’s picture

Yeah, it's just that the presence of the block table seems more tied to the API than the UI.

Anyway, if the block table isn't there when block.module is uninstalled then yes we have to guard our references to it.

Adam S’s picture

StatusFileSize
new3.72 KB

Here is a patch to hide the block name/description and block level caching options.

dawehner’s picture


-        if (module_exists('block')){
-          $this->update_block_bid($form_state['view']->name, $this->display->id, $this->display->new_id);
-        }

This was part of your previous patch not views itself.

merlinofchaos’s picture

I don't think I would hide these options. Some other block interface might still use that data, if it's using block APIs.

Adam S’s picture

StatusFileSize
new2.78 KB

Sorry about that.

merlinofchaos’s picture

Another issue: block.module could be enabled, creating a block table. Then disabled. The table will still exist until block.module is uninstalled. If you change something, and block table does not get updated, then when block.module is re-enabled the data will be out of sync.

I think we actually need to use something like

if (module_exists('block') || db_table_exists('block')) { }
Adam S’s picture

StatusFileSize
new1.72 KB

I don't think I would hide these options. Some other block interface might still use that data, if it's using block APIs.

Oh, I see. This information is exposed to the API through views_block_info() and views_block_view(). Therefore, the only point of saving it to the blocks table is if the Blocks UI is enabled to be overridden on the blocks configuration page.

merlinofchaos’s picture

Status: Active » Needs work

Right but what about, say, CTools content types? They use the same data even though block module may be disabled. Ok not the block caching, but it *could* use it. Certainly the block description.

Adam S’s picture

StatusFileSize
new1.77 KB

It shouldn't matter if the Block module is enabled or not because if the Block module is enabled and the block table doesn't exist the site wouldn't work. So for brevity sake the module_exists('block') condition might safely be left out.

In views_block_info(), the info and cache properties were set by Views based on the description and block cache settings in the View while the Block module was disabled and uninstalled.

merlinofchaos’s picture

For brevity yes.

But for performance reasons, no: module_exists() is a fast check. db_table_exists() is slow.

module_exists() guarantees db_table_exists. Therefore we increase performance by checking the module first.

dawehner’s picture

+++ b/views_plugin_display_block.incundefined
@@ -190,25 +190,27 @@ class views_plugin_display_block extends views_plugin_display {
   function update_block_bid($name, $old_delta, $delta) {
-    $old_delta = $name . '-' . $old_delta;
-    $delta = $name . '-' . $delta;
-    if (strlen($old_delta) >= 32) {
-      $old_delta = md5($old_delta);
-    }
-    if (strlen($delta) >= 32) {
-      $delta = md5($delta);
+    if (module_exists('block') || db_table_exists('block')) {
+      $old_delta = $name . '-' . $old_delta;
+      $delta = $name . '-' . $delta;
+      if (strlen($old_delta) >= 32) {
+        $old_delta = md5($old_delta);
+      }
+      if (strlen($delta) >= 32) {
+        $delta = md5($delta);
+      }
+      db_update('block')
+        ->fields(array('delta' => $delta))
+        ->condition('delta', $old_delta)
+        ->execute();
     }
-    db_update('block')
-      ->fields(array('delta' => $delta))
-      ->condition('delta', $old_delta)

This shouldn't be part of the patch.

dawehner’s picture

+++ b/views_plugin_display_block.incundefined
@@ -190,25 +190,27 @@ class views_plugin_display_block extends views_plugin_display {
-    if ($bid = db_query("SELECT bid FROM {block} WHERE module = 'views' AND delta = :delta", array(
+    if ((module_exists('block') || db_table_exists('block')) && $bid = db_query("SELECT bid FROM {block} WHERE module = 'views' AND delta = :delta", array(
         ':delta' => $delta))->fetchField()) {
       db_update('block')
         ->fields(array(

So here is a real review: If module_exists than the table exists as well, so it would be enough to check for the db_table_exists

dawehner’s picture

Status: Needs work » Fixed

Okay commtied the idea from #18

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.