Configuring subscriptions for mailouts is nice for many uses. On one project, I have a requirement to match a search form where the selection criteria has to be joined with and instead of or. I created a little module to execute views from the subscriptions queue so I could use all the features of views. if it is of interest, I can submit it for your use or add it to my sandbox.

The module has an outline at http://petermoulding.com/subscriptions_mail_from_view

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

salvis’s picture

Yes, I'm very interested in this!

According to the docs on your site you require some patches in Subscriptions. I'd suggest to put this module under subscriptions/contribs/subscriptions_mail_from_view and to post a single-file Subscriptions patch for now. This is easiest for reviewing and maximizes your exposure.

You can still decide whether you want to contribute it to this project (with acknowledgement in Subscriptions' README.txt file and documentation in its own README.txt file, but no copyright notices or license terms and no ads in the source code), or to create a project of your own.

peterx’s picture

Here is the patch to subscriptions_menu_cron to add hook subscriptions_menu_preload_queue. My code responds to the hook. I do not think there will be any other changes to current code.

It would be possible to abstract out the mail queue selection and reuse it but my module is not yet stable to the point where I could make a change like that. Using the same time is the only variable at this stage. I do not know if the time has to be exact. A long running process might have a few seconds between selections and that should not do anything major. Using a fixed time and passing it through the hook is purely to guarantee the view will use the same selection as the mail cron.

peterx’s picture

FileSize
4.22 KB

Added module under contribs. The module defines a table and consumes entries in the table. It does not generate entries in the table.

I tried generating a patch to add files but the patch program said no so I zipped it. It is a start for you to look at.

peterx’s picture

FileSize
4.56 KB

The previous code works with one selection criteria. I expanded the filter code to handle multiple filters and multiple values for filters and logging warnings when filters are not found.

salvis’s picture

Status: Active » Needs work

Sorry, but zipping your files moves this to the bottom of my stack. The first step in evaluating a patch is to let the testbot try to apply it. If it doesn't apply there's no point in going any further.

You'll want to learn how to use Git sooner or later anyway. Please do it now, and you'll never regret it. The git diff command effortlessly creates a compatible patch.

peterx’s picture

Winmerge creates a patch from files but only if a file exists on both sides. Meld does not work on Windows and the Meld in my Ubuntu machines does not do directory level patches. Smartgit, Netbeans, etc, will commit a patch to a Git repository but not generate a patch file. The only documentation I can find for directory level patches mentions those funny Unix DOS commands but does not explain how they work, which means wasting time on trial and error.

I might leave the extra module until next week after I finish work on the code to generate view requests. I can then bash the code with some extensive tests and see what breaks. The hook from Subscriptions mail cron will not change and that can go ahead. Do you want me to create a documentation page on the hook? Give people examples of use?

KarinG’s picture

Hi Peter - I use diff (will work on any Unix install). I look forward to starting to test your work. From the man pages:

2) CREATING PATCHES WITH DIFF
-----------------------------

In a shell, change to the directory where the file you wish to make a
patch for is located. Copy the original file (before your edits) to
the same directory (you *did* make a backup copy of it before you
edited it, right?). Now, type in the shell:

diff -uN original_file new_file >patch.original_file

where original_file is the filename of the original file and new_file
is the filename of the new file (the one containing your edits).

This technique also works for creating a patch for a whole directory
tree (e.g. creating a Linux kernel patch). Just add the -r flag to
your diff command:

diff -uNr original_dir new_dir >patch.original_dir

Here is a concrete example of creating a patch against the vanilla
Linux kernel's source tree:

cd /usr/src
diff -uNr linux-2.4.19 linux-2.4.19-my_version \
          >patch.linux-2.4.19-my_version

That is all there is to creating patches with diff. Move on to Step 3
to see how to apply them with patch.

KarinG’s picture

Or do take a leap and install git on your Unix machine and use

git diff

This is pretty good info on how to get started with git:
http://drupal.org/node/707484

peterx’s picture

@KarinG: My machine is: 2 * Windows + 4 * Ubuntu but most of my time, and my current subscriptions project, is on Windows 7.

Mail from view delayed another day. I ran up a Subscriptions mail from Apache Solr search module. Will open a separate issue.

KarinG’s picture

All your hard work on any Drupal project will only pay off if you can mold it into patches! This would be super quick:

On one of your ubuntu machines just do a
git clone of subscriptions module - 7.x-1.x-dev

Then copy the entire subscriptions dir from your W7 machine to your ubuntu box. And then run a diff -uNr between the two directories.

peterx’s picture

FileSize
11.69 KB

I copied everything to a *nix box and did battle with the DOS command line then looked at the format of the patch. Turns out there is nothing special. It is exactly the same as concatenating patches of the individual files. I can do it in Winmerge with less work.

salvis’s picture

Status: Needs work » Needs review

Thank you! Set the status to NR to activate the testbot.

Status: Needs review » Needs work

The last submitted patch, subs_view.patch, failed testing.

salvis’s picture

peterx:
You'll be much happier if you use the tools that everyone else uses. We have chosen them because they work and they fit our workflow. There may be a little learning bump at the start, but it's smooth sailing afterwards.

peterx’s picture

This version has the views.inc as per the Solr module. been through coder.

KarinG’s picture

Status: Needs work » Needs review
KarinG’s picture

salvis asked me to test this. I've applied your patch to our latest dev on my local MAMP stack. Tell me in a nutshell what I should be doing / where I should be looking to test the functionality of your code additions. We'll be able to use this as well to add to the documentation of this new addition.

peterx’s picture

Hello KarenG, I started documentation at http://petermoulding.com/subscriptions_mail_from_view. Can copy it to a page at Drupal.org.

Create a view with exposed filters. Use phpMyAdmin, or equivalent, to insert a row in subscriptions_mail_from_view table. You put the view machine name in the view column. You put the information for the filters in the filters column. You run cron. subscriptions_mail_cron will use the new hook to call the cron bit in Subscriptions mail from view. My module reads the view information, runs the view, gets the node ids from the view, and inserts rows in the queue then returns to subscriptions_mail_cron where the nodes are mailed out.

The other columns in subscriptions_mail_from_view table become the values for the columns in the queue rows. There may be an example insert in the head of the class file. If not, I will add one here when I hit the office.

KarinG’s picture

Ok it's all about details now:

Create a view with exposed filters.

1. Ok, I've created a View - Page display w/ Fields Title and NID - with exposed Filter - Taxonomy: Term (exposed). It works - if I type in Drupal I see my Drupal projects.

2. Enabled Subscriptions Mail from View in admin/modules -> Save configuration.

Use phpMyAdmin, or equivalent, to insert a row in subscriptions_mail_from_view table.

3. This will not be feasible for most people using subscriptions.module - this will need to go into a /config

You put the information for the filters in the filters column.

4. What exactly needs to go into the filters column? The Structure is text. It's not clear.

Let me know.

peterx’s picture

I have a view with an exposed filter on title and set to contains. The uploaded code should work with filter set to:
title=pur

The new code I am using will allow multiple selection of the form:
title:pur|uid:165+195
I am currently working on the Solr code and backporting to the view version.

KarinG’s picture

OK,

I've changed my filter criteria to: Content: Title (exposed) - set to contains. Tested it - is working fine.

4. In table {subscriptions_mail_from_view}: inserttest_patch = from table:field view_view:name into view field and
title=pur into filters field

5. Running cron.

6. Making an update on my About page that I'm subscribed to. Running cron again - confirming that I'm indeed receiving a notification for this update. I'm in the view -> filter -> Apply -> I'm getting two results in the filter. Running cron again. Updating the About page again. Running cron again.

If I edit the About page I get an entry in {subscriptions_queue}. If I go to my view page display -> and filter -> Apply -> nothing gets added to the {subscriptions_queue}

So what should I be seeing/where? What can I do now that I couldn't do previously? You need to be very specific.

peterx’s picture

I am working through use cases and testing on the solr version at a site. I saved the last stable code to http://drupal.org/sandbox/peter/1697174 and will add the next iteration after the solr changes. I think the main bit to do is document the setup of a view. Everything else, including selection criteria in the view, is really Views stuff and this module should be stable.

Everything shared between this module and the solr module is moved out to Subscriptions mail from.

salvis’s picture

Status: Needs review » Needs work

AFAICS this is not ready for review.