Jump to content

IPS Rules Application


Recommended Posts

11 hours ago, Sull5 said:

@Kevin Carwile, how can I create a condition, if a file has been attached to a forum post ?

Thanks 

That's not so easy. But I'll give you the solution anyway in case you are the adventurous type.

The attachments aren't actually "attached" until after the content created/updated events have happened (internal ips workflow thing). So you can't check the condition on a rule attached directly to one of those events because the attachment won't actually have been claimed yet. Also, there is no stock condition to check if a topic or post has an attachment, so it would require a custom php snippet to do that.

So... for the solution:

You need to first create a custom action which you will trigger from a rule when the content is created/updated and set the action execution to wait until the end of the page load so that the "attachment" can be processed before your custom action is actually fired. And then you would check the condition in your custom action rule.

The custom php code portion of the condition would look like this (this means you need to add an argument to your custom action called "Content", which would either be a content item class or a content comment class, and would make $content available to your custom php code):

/**
 * If content being checked is a topic/item, check if any post has an attachment 
 */
if ( $content instanceof \IPS\Content\Item )
{
	$locationKey = $content::$application . '_' . ucfirst( $content::$module );	
	return (bool) \IPS\Db::i()->select( 'COUNT(*)', 'core_attachments_map', array( 'location_key=? AND id1=?', $locationKey, $content->activeid ) )->first();
}

/**
 * If content being checked is a post, see if it has an attachment 
 */
else if ( $content instanceof \IPS\Content\Comment )
{
	$item = $content->item();
	$locationKey = $item::$application . '_' . ucfirst( $item::$module );	
	return (bool) \IPS\Db::i()->select( 'COUNT(*)', 'core_attachments_map', array( 'location_key=? AND id1=? AND id2=?', $locationKey, $item->activeid, $content->activeid ) )->first();
}

return FALSE;

 

Edited by Kevin Carwile
Link to comment
On 2/28/2016 at 4:30 PM, NoGi said:

Does this work with Adv Tags and Prefix? I use that in my sales forum and have a prefix that is SOLD. I'd like the topic to close if the prefix is changed to that.

 

5 minutes ago, Kevin Carwile said:

Yes, it will work.

Nice use!

Edited by chilihead
Link to comment

I'm stuck on the how to check for the prefix as being sold

 

Rule: Auto close on sold items Disabled

  • Event: Topic has been created or updated
  • Conditions:
    • Content attribute values (Check for SOLD prefix)
  • Actions:
    • Lock content (Close Topic)Rule: Auto close on sold items Disabled
    • Event: Topic has been created or updated
    • Conditions:
      • Content attribute values (Check for SOLD prefix)
    • Actions:
      • Lock content (Close Topic)

 

 

 

Link to comment

Try creating a custom action to check for the sold prefix on the topic and close it, and then trigger that custom action from your rule when a "topic has been created or updated". And make sure to set the action execution to the "end of page load" setting.

I believe the problem you are having is because of a timing nuance. When the topic is created/updated with new tags, then the event actually happens before the tags are saved to the topic in core processing.

Link to comment
  • 2 weeks later...

If dev mode is enabled, the app breaks the site because an E_NOTICE is emitted by line 435 of your ipsPatternsActiveRecord hook (__set) when you try to get an undefined index from _data (because it's being set for the first time). You should probably add an array_key_exists or isset check there to prevent that error.

Also, can you add some indexes to the Rules tables? The queries are currently fairly slow, and adding an index should help quite a lot.

Edited by Colonel_mortis
Link to comment
  • 4 weeks later...

Ah great, ive installed this lite version now...

looks great! 

Have downloaded the example rules and trying to set up member engagement.

Looking at Scheduled Actions I see Send a re-engagement email to the member listed 5 times. 

Is this normal behavior?

 

 

Link to comment
  • 2 weeks later...
8 minutes ago, Jesse Rapczak said:

Hi Kevin,

I'm using the forms app with your Rules app and I'm trying to come up with a way to not let a user submit a form unless it checks the currently logged in member for my 'steamid' variable and only lets them submit it when it finds that the steamid isn't 0. Any ideas?

Not really possible I dont think. You can perform the check after the form is saved, but you can't do on the fly form validation like that.

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...