Extension, Module

Archived
Forum
(read-only)

Mustash

ExpressionEngine 2, ExpressionEngine 3, ExpressionEngine 4, ExpressionEngine 5, ExpressionEngine 6

Back to this add-on's main page
View Other Add-ons From Mark Croxton

     

Database Error - exp_stash_rules group_id

Bug Report

Fuel Integrated
Fuel Integrated

Hi Mark,

I’m getting this error when trying to save a cache breaking rule, Mustash 1.1.2

Incorrect integer value'NULL' for column 'group_id' at row 1

INSERT INTO 
`exp_stash_rules` (`plugin`, `hook`, `group_id`, `bundle_id`, `scope`, `pattern`, `ord`, `site_id`) VALUES ('clear_module_page''stash_delete''NULL''5''site''#^(.*){url_title}(.*)$#'5'1')

Filenamethird_party/mustash/models/mustash_model.php

Line Number
574 

Worked fine up until I updated, this is with the custom stash_delete hook plugin thing, which doesn’t let me select a group in the UI when entering the rule info.

Mark Croxton
# 1
Developer
Mark Croxton

Do you have this in your custom plugin?

/**
  * Set groups for this object
  *
  * @access protected
  * @return array
  */
 
protected function set_groups()
 
{
  
return array();
 
Fuel Integrated
# 2
Fuel Integrated

Yep, here’s the file:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Mustash cache-breaking plugin
 *
 * @package Mustash
 * @author      Mark Croxton
 */

class Stash_clear_module_page_pi extends Mustash_plugin {

    
/**
     * Name
     *
     * @var     string
     * @access  public
     */
    
public $name 'Module pages';

    
/**
     * Version
     *
     * @var     string
     * @access  public
     */
    
public $version '1.0.0';

    
/**
     * Extension hook priority
     *
     * @var     integer
     * @access  public
     */
    
public $priority '10';

    
/**
     * Extension hooks and associated markers
     *
     * @var     array
     * @access  protected
     */
    
protected $hooks = array(
        
'stash_delete'
    
);

    
/**
     * The 'Tags' bundle ID
     *
     * @var     integer
     * @access  protected
     */
    
protected $bundle_id 5;

    
/**
     * Constructor
     *
     * @return void
     */
    
public function __construct()
    
{
        parent
::__construct();
    
}

    
/**
     * Set groups for this object
     *
     * @access  protected
     * @return  array
     */
    
protected function set_groups()
    
{
        
return array();
    
}

    
/*
    ================================================================
    Hooks
    ================================================================
    */

    /**
     * Hook: stash_delete
     *
     * @access  public
     * @param   array
     * @return  void
     */
    
public function stash_delete($data)
    
{
        
if ($data['bundle_id'== $this->bundle_id)
        
{
            
// prep marker data
            
$markers = array(
                
'url_title' => $data['key_label']
            
);

            
// flush cache
            
$this->flush_cache(__FUNCTION__FALSE$markers);
        
}
    }
Mark Croxton
# 3
Developer
Mark Croxton

What version of EE? Have you upgraded anything recently?

Fuel Integrated
# 4
Fuel Integrated

EE 2.9.0, updated a bunch of things :/

Mark Croxton
# 5
Developer
Mark Croxton

Hmm weird one. I can do some testing with your plugin tomorrow see if I can reproduce. What PHP version?

Fuel Integrated
# 6
Fuel Integrated

Currently running PHP Version 5.5.27-1+deb.sury.org~precise+1 in vagrant

Mark Croxton
# 7
Developer
Mark Croxton

I can’t reproduce it no matter what I try!

It seems like NULL is not getting filtered out of the array inserted into db, for whatever reason. Try this:

around line 657 of mcp.mustash.php change this:

if ( $trigger != "NULL" 

to this

if ( $trigger != "NULL" && ! is_null($trigger) ) 
Fuel Integrated
# 8
Fuel Integrated

Just tried it, and didn’t work :(
Upon saving, the same error showed up and it removes every cache rule after the last rule with a group specified.

Mark Croxton
# 9
Developer
Mark Croxton

OK please undo the last change and try this line 664 just a bit below:

'group_id' => $group[$index]

To:

'group_id' => ($group[$index] == "NULL" NULL $group[$index]), 
Fuel Integrated
# 10
Fuel Integrated

Yep, that seems to have done it!

In previous versions, group_id was previously 0 for stash_delete, now obviously it’s being set to NULL - though I guess that will have the same falsey result anyway.

Cheers!

doctorlove
# 11
doctorlove

I had the same errors when creating cache breaking rules and leaving group, bundle and scope blank.

I have now done the same for bundle_id and scope, which results in:

'group_id' => ($group[$index] == "NULL" NULL $group[$index]), 
'bundle_id' => ($bundle[$index] == "NULL" NULL $bundle[$index]), 
'scope'  => ($scope[$index] == "NULL" NULL $scope[$index]), 

Is this bad practice? Why isn’t this possible out of the box?

Mark Croxton
# 12
Developer
Mark Croxton

It is possible of course, but you and the OP seem to have an environment-specific configuration that makes it throw an error. Not sure what exactly as I’m not able to reproduce, and no one else has reported a problem.

However, as the solution above seems to work for you both, I have rolled it into the latest release which you can download now from your account. (v1.1.3)