Scheduling publishing

heruraha

Joined: 2006-02-22
Posts: 21
Posted: Wed, 2006-03-15 01:12

When I was still using Gallery 1.4.2, I had put a really gnarly hack in place that allowed me to specify a Publish Date when I created a Gallery, storing the album ID and publish date in a SQL database, and then checking those dates in the albums view, if the publish date was greater than the current date, the album would not display.

I'd like to modify my Gallery 2 installation in the same way. I was very pleased to see that G2 now supports third-party modules, but I haven't spent enough time looking at the code to understand how I would create a module to do this.

Is there already a module for publication scheduling, and if not, can someone get me pointed in the right direction to begin coding my own (which I will happily share, when finished)???

Thanks!!!

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Wed, 2006-03-15 16:52

there has been some talk about publishing, but no code that i know of.

start with lib/tools/creator to help you create your own module.

Here is one possible way to support publishing:
- module has an ItemEditOption to add a form on the General tab of ItemEdit to set publish and/or expire date for items.
- dates are stored as plugin parameters for your module
- when either date is set, the option adds an onLoadHandler for the item.
- this handler checks the current time against the publish/expire time and takes any action that is needed, removing its own handler once the action is taken
- i guess publish adds core.viewAll permission for Everybody group, expire removes core.viewAll.. or maybe a site admin option to choose whether you publish with viewAll or just view/viewResizes.

 
heruraha

Joined: 2006-02-22
Posts: 21
Posted: Wed, 2006-03-15 18:05

Thanks, I appreciate the tips!

 
athertop

Joined: 2003-08-06
Posts: 38
Posted: Thu, 2006-03-30 15:17

I'd really appreciate if you do develop a solution to this one if you'd let me know as it would be a 'must have' for a new site I am looking at putting together, and this is a show stopper for me using Gallery 2 at the minute.

Thanks,
Paul

 
DivaShane

Joined: 2006-10-14
Posts: 3
Posted: Tue, 2006-10-24 17:32

Any news on a publish by date module? I would love to have one.

 
heruraha

Joined: 2006-02-22
Posts: 21
Posted: Sat, 2007-02-03 03:29

I'm making headway with this module, basing most of my work on the "Hidden Items" module that comes prepackaged with G2.

I've successfully got it operating as essentially a cloned module of Hidden Items with file/directory/variable names changed, and I figured the easiest way to do this is to tie it into the "Date and Time" function that is already in ItemEditItem (saved to the DB as originationTimestamp, if I'm grokking the structure here....)

I think all I need to do still is add this bit of code:

$timestamp = $item->getOriginationTimestamp();
if ($timestamp <= time()) {
unScheduleItem($item);
}

But I'm not entirely sure where it would go... I'm posting this in the hopes that I may hear a response back before I can figure it out on my own.

Thanks for a great program, I look forward to making my small contribution to the code community when this is done.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Sun, 2007-02-04 00:08

you probably don't want to use origination timestamp to store when to publish the item, as that field is already used and has its own meaning. maybe set the timestamp as a plugin parameter.
the tricky part of this module is how/when to check for things that need publishing.. you can look at modules/addviaemail in gallery-contrib for a couple ideas.. this module has two ways to invoke its check-mailbox routine: a block you can add to your theme and a special view you can request via cron.

 
heruraha

Joined: 2006-02-22
Posts: 21
Posted: Mon, 2007-02-05 22:57

Ok, thanks for the tips... but I'm not entirely clear on why it would be bad to use origination timestamp, it seems to me that if you're going to schedule an album to publish a week from today, you would want the origination timestamp to reflect that future date, and it seems simpler to use the existing field than to create a new parameter which you would want to hold the same data as originationtimestamp already does. And having this module active won't necessarily make a post-dated album invisible, only if the "schedule for later publication" checkbox is checked. Maybe I'm missing something...

Thanks for the info, hopefully it will be enough to get this module working...

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Tue, 2007-02-06 18:10

origination timestamp is the time the content of this item was created.. ie, the capture date for a photo or movie, the date a document was written, etc. typically this value is read from the EXIF data of jpeg photos. otherwise it defaults to when the item was created in G2.. you can also edit this value in edit item / General tab.

 
rotpar

Joined: 2007-02-26
Posts: 47
Posted: Mon, 2007-04-02 10:17

Any news on this module yet? I'd love to have this feature in my site.

 
heruraha

Joined: 2006-02-22
Posts: 21
Posted: Wed, 2007-04-18 02:01

Could you please point me towards some code that can help me understand registering and reading plugin parameters in G2?

 
heruraha

Joined: 2006-02-22
Posts: 21
Posted: Wed, 2007-04-18 03:23

The following code is resulting in an empty newPublishTimestamp variable... any idea what I'm doing wrong?

$newPublishTimestamp = mktime($form['publishTimestampSplit']['Time_Hour'],
$form['publishTimestampSplit']['Time_Minute'],
$form['publishTimestampSplit']['Time_Second'],
$form['publishTimestampSplit']['Date_Month'],
$form['publishTimestampSplit']['Date_Day'],
$form['publishTimestampSplit']['Date_Year']);
$ret = GalleryCoreApi::setPluginParameter('module', 'schedule',
'publishDate', $newPublishTimestamp, $item->getId());

 
heruraha

Joined: 2006-02-22
Posts: 21
Posted: Wed, 2007-04-18 03:45

my bad I'm an idiot... I was putting that code in the Helper.class file instead of the ItemOption.inc file... its working now... I'm getting really close, if someone reads this in the near future I just need to figure out how to read back from the PluginParameter I just set and how to make sure the form I created on the ItemEditItem page reflects the PluginParameter as the default instead of the current date and time (I snagged the date/time form code from the originationTimestamp form, renamed to publishTimestamp)

Thanks for the tips, mindless, and anyone else who may jump in before this is done. I think I'll have this module available to the public for use and improvement within 48 hours :)

 
heruraha

Joined: 2006-02-22
Posts: 21
Posted: Thu, 2007-04-19 02:01

Okay gonna try this again with a little more specificity...

I've successfully got the module hiding anything with an onLoadHandler of "Scheduled", and a PluginParameter that contains the publication date, but I can't seem to figure out exactly how the onloadHandler works... is it checking for this onLoadHandler every time the album is loaded, and does it need to be directly accessed in order to trigger the onloadHandler? Does it trigger the onLoadHandler if I'm in the parent folder that contains the scheduled item (looking at its thumbnail, not in the scheduled album yet)?

If so, it seems like the onLoadHandler should be able to check the current date against the pluginParameter and if the scheduled date has been hit, it should unhide/publish the album and remove the onLoadHandler, right?

I can upload my source if it helps... sorry if I'm a pain in the ass with this, I just know I'm close and lots of people have been asking for this feature so I'd like to finish this project ASAP.

Thanks!!!

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2007-04-20 01:20

onLoadHandler is called whenever that entity is loaded. So, if it's the album page for that album you're sure it will be called.. however, it can be called many other ways too (thumbnail shown in parent album, even random image block). So the code for the onLoadHandler should can the current view and itemId parameters to make sure this is core.ShowItem for this item, before taking action. (though in the case of scheduled publish, maybe it doesn't matter... if it's time to publish, doesn't really matter how it was referenced)

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2007-04-20 12:21

So you're using the onLoad handler just as trigger to check if it's time to publish/expire the item? Just as a replacement for a cron job?

But if you do the actual publishing/expiration by adding/removing the "view all" permission, why should the onLoad handler ever be called? It would only be called if an admin is browsing the site...
I guess I don't understand your approach.

--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage

 
heruraha

Joined: 2006-02-22
Posts: 21
Posted: Sat, 2007-04-21 02:08

Okay, thanks for the replies guys, I'm still trying to decipher the workings of Gallery... I think maybe I've been misunderstanding what onLoadHandler is and how it works.

I based my original code on the "Hidden Items" module so it is adding/removing the view permissions. It sets an onLoadHandler of |Scheduled| (|Hidden| in the original code) for that item in the database. I assumed that this meant that every time gallery goes to load that album/item, it checks to see if it has an onLoadHandler of Scheduled (or Hidden), and if so it sets the permissions so the item doesn't display. It seemed logical that the same function that checks to see whether or not it is Scheduled can also check its Publish date from the PluginParameters, and if necessary remove the onLoadHandler and begin displaying the item regularly. However, it appears I'm still not quite getting how this function works.

I'm starting to think a cron job is the best way to handle publication, though I admittedly have no experience with cron, so I'm back to the research for a while. Is there any existing work/documentation re: cron+G2 that you can point me towards? I really appreciate all your guys' help and I don't want to keep bugging you with dumb questions.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Sat, 2007-04-21 20:41

this approach works for hidden items because the way to see a hidden item is to use the URL directly for that item.. thus G2 loads the item and the handler is run.. permission can be granted.

in your case people are browsing albums that may contain items ready to publish... since general users/guests don't have permission for the unpublished items they won't be loaded by G2, handler to publish them doesn't run.. (until an admin browses, as valiant mentioned).

we don't have any cron like facility yet, so anything in that area will be breaking new ground.. but of course cron is the right model for publish/expire. the only alternative that comes to mind is putting an onLoadHandler in the parent of the item to-be-published.. each time that album is loaded (by users/guests) it could scan the child items to see if any should be published now. not ideal, but maybe workable in the current system.

 
heruraha

Joined: 2006-02-22
Posts: 21
Posted: Wed, 2007-04-25 00:42

Got it, thanks... I found a nice little open source util called php-pseudo-cron that I can integrate so we don't have to worry about folks who don't have access to cron. Thanks again for all your help, I think I can figure it out from here :)

 
heruraha

Joined: 2006-02-22
Posts: 21
Posted: Wed, 2007-07-04 11:43

I think I've finally got this cracked, but I've hit one final obstacle.

I tried adding a function for getItemSummaries to my module.inc, primarily because I wanted to allow admins to see the scheduled date when an album is set to publish at a glance, and that works.

Well, it got me to thinking that I could use the same getItemSummaries function to affect code displayed for every album, scheduled or not - so I decided to embed my pseudo-cron job in there... basically, once in every few hundred times the getItemSummaries function is called, it will check the PluginParameters to see if any scheduled albums have a publish date greater than or equal to the current date/time. That worked, and my query returned the IDs of albums which needed to be published.

Unfortunately, when I called unScheduleItem, I got an error because I wasn't passing the actual item to the function, just the itemId... since getItemSummaries isn't calling the item in question, I'm not sure what to do. Is there a way to invoke an instance of an item with its ID number, so I can pass it to this function?

Please say yes... if so, I'm done with this puppy - otherwise, I've got to find a different way to do this. I'm not sure how to go about using the onLoadHandler in the parent function, any tips would be helpful, I constantly get lost in the code of this program when I go exploring :)

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Thu, 2007-07-05 03:01

don't really understand your unScheduleItem question.. if you have an itemId and want the item, use GalleryCoreApi::loadEntitiesById. if that doesn't help, please explain is more detail what is calling what, etc...

 
heruraha

Joined: 2006-02-22
Posts: 21
Posted: Tue, 2007-07-31 07:30

I was getting a "member function on a non-object" error, if I remember the wording correctly... loadEntitiesById worked, and the module is doing exactly what it's supposed to now! Huge thanks to mindless and valiant for your help with my incessant questions.

I'm gonna go do some more testing on this, once I'm sure everything is relatively copacetic I'd like to release this code to the public for use and improvement - some of my code is a little wonky, I'm sure the experts can clean it up a bit, but it WORKS! Haha... sorry, just a little excited to have this finally done. How can I submit this module to the community?

EDIT: I have attached a .ZIP file with my functional module as it exists now.

EDIT 7/30/07 - New .ZIP file uploaded, ScheduleHelper.class was causing errors with recursive scheduling of children.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Sat, 2007-07-07 15:03

congrats on the first release!

to start with, you can add an entry at http://codex.gallery2.org/Gallery2:User_Contributions and link to the attachment here. if you like, you can request access to gallery_contrib project on sourceforge.net and you can commit your module there. this will allow you to release the module via the "downloadable plugins" feature of gallery 2.2.x.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Wed, 2007-07-11 23:18
Quote:
add an entry at http://codex.gallery2.org/Gallery2:User_Contributions and link to the attachment here

Done.

This is Cool!
I have created a codex page as well:
http://codex.gallery2.org/Gallery2:Modules:schedule
feel free to add and or edit.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
chivas12

Joined: 2005-05-31
Posts: 43
Posted: Wed, 2007-08-29 02:41

Hi heruraha, I'm interested in your schedule function. But there are some errors when running it.

-----------------------------------------------
My Album:Photo Album

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Wed, 2007-08-29 02:56
 
julandy

Joined: 2007-08-30
Posts: 3
Posted: Thu, 2007-08-30 18:13

Hi Heruraha, great idea you got here.

I wanted the same and at first guessed the date function worked like my Wordpress blog post date function, but sadly not. Got VERY excited at finding your module but sadly in Gallery 2.2.2 it just comes up with:

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

This is after I activeate the module and try and return to the root gallery from the admin page. I'm quite new to Gallery2, a few months of tinkering, and I assume I just ftp the folder called 'schedule' from your zip in the 'modules' folder on my Gallery2 install? Please correct me if I'm wrong.

This module really does need to be developed to a full working, stable module for release. Help alot of people especially those bloggers who like to link posts (future dated) to their related gallery. Keep the two in sync, if you get my drift.

Keep up the excellent work and hopefully we'll have want we want. Sadly I have no php coding knowledge to contribute.

Thanks again.

J

 
camerapassion

Joined: 2007-10-08
Posts: 1
Posted: Mon, 2007-10-08 17:26

Hi Heruraha

Great and important plugin, but on my testing site dont work. All other (incl. 3d party) works with no problems. I still have screen with:

Access denied for user 'root'@'localhost' (using password: NO)

Regards

Pawel

 
kiev

Joined: 2007-10-16
Posts: 3
Posted: Wed, 2007-10-17 09:34

Thank you for FAQ. I look forward to learning more as you write.
секс

 
tomsche

Joined: 2008-05-03
Posts: 1
Posted: Sat, 2008-05-03 01:15

I got the same message:

Quote:
Access denied for user 'root'@'localhost' (using password: NO)

Did anyone find a answer to this problem?

Thomas

 
weslemos

Joined: 2007-01-26
Posts: 5
Posted: Mon, 2009-08-17 15:42

I just installed this module as well and I too have the same problem.

Quote:
Access denied for user 'root'@'localhost' (using password: NO)

I'm not a programmer but I'll look into seeing if I can find a solution... but if someone else already has one, that would be awesome!

Wes

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Tue, 2009-08-18 00:15

For anybody that wants to get their feet wet and continue on this module:
One of the first steps needed is:
* Error handling pattern changed. Old:

 if ($ret) { 
   return $ret->wrap(__FILE__, __LINE__); 
 }

new:

 if ($ret) {
   return $ret;
 }

http://codex.gallery2.org/Gallery2:API_Changes_From_2.0_To_2.1

good luck,

Dave

_____________________________________________
Blog & G2 || floridave - Gallery Team

 
simon_b

Joined: 2010-01-19
Posts: 8
Posted: Tue, 2010-01-19 15:30
Quote:
Got VERY excited at finding your module but sadly in Gallery 2.2.2 it just comes up with:

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Same here, I get that error too. Has anyone found some kind of solution for this? One thing I can think of is that I am using a remote database on a different server to the files, not 'localhost'.

Also, my database has been setup not be accessible from outside my host. Is this a factor?