solved SOLVED - Hide or Delete past events

MAD
MAD
@madc
10 years ago
600 posts
As the title says.
What would I need to do to either automatically hide or delete past events.



--
~ https://punkbandpromotions.com ~
Check us out for all your Punk/Alternative Music!
Check us out on Facebook:- https://facebook.com/PunkBandPromotion

updated by @madc: 04/12/14 10:15:35PM
paul
@paul
10 years ago
4,326 posts
To stop them from being listed put the following search in the jrCore_list -
search="$smarty.now < $event_date"


--
Paul Asher - JR Developer and System Import Specialist
MAD
MAD
@madc
10 years ago
600 posts
I would need to put that in on every update then @paul?


--
~ https://punkbandpromotions.com ~
Check us out for all your Punk/Alternative Music!
Check us out on Facebook:- https://facebook.com/PunkBandPromotion
paul
@paul
10 years ago
4,326 posts
In every template that lists events, yes.
If there's already a search in the call, use search2 or search3.
Hth
Pa


--
Paul Asher - JR Developer and System Import Specialist
MAD
MAD
@madc
10 years ago
600 posts
Ouch. Do the events stay showing by default forever then unless you do that?
Is there any plans to make this a selectable feature as past events are useless to us.


--
~ https://punkbandpromotions.com ~
Check us out for all your Punk/Alternative Music!
Check us out on Facebook:- https://facebook.com/PunkBandPromotion
paul
@paul
10 years ago
4,326 posts
It probably won't be a module option, but I do think that all skin templates ought to only show future events by default, then maybe an option on the profile sites to show past events, so that artists can optionally keep their events as an archive.
I'll raise it with the team.
Thanks


--
Paul Asher - JR Developer and System Import Specialist
paul
@paul
10 years ago
4,326 posts
Alternatively it would be a simple custom module to automatically delete past events.


--
Paul Asher - JR Developer and System Import Specialist
MAD
MAD
@madc
10 years ago
600 posts
The latter would be perfect for us!


--
~ https://punkbandpromotions.com ~
Check us out for all your Punk/Alternative Music!
Check us out on Facebook:- https://facebook.com/PunkBandPromotion
paul
@paul
10 years ago
4,326 posts
OK - A module with just an include.php file something like this -

<?php
// make sure we are not being called directly
defined('APP_DIR') or exit();

/**
 * meta
 */
function xxDeletePastEvents_meta(){
    $_tmp = array(
        'name'        => 'Delete Past Events',
        'url'         => 'deletepastevents',
        'version'     => '1.0.0',
        'developer'   => 'Whoever, &copy;' . strftime('%Y'),
        'description' => 'Listens for the "daily" event then deletes all jrEvent items that are past',
        'category'    => 'site'
    );
    return $_tmp;
}

/**
 * init
 */
function xxDeletePastEvents_init(){
    jrCore_register_event_listener('jrCore','daily_maintenance','xxDeletePastEvents_listener');

    return true;
}

//---------------------------------------------------------
// EVENT LISTENERS
//---------------------------------------------------------

/**
 * @param $_data array incoming data array
 * @param $_user array current user info
 * @param $_conf array Global config
 * @param $_args array additional info about the module
 * @param $event string Event Trigger name
 * @return array
 */
function xxDeletePastEvents_listener($_data,$_user,$_conf,$_args,$event)
{ // Is there a jrEvent module? if (jrCore_module_is_active('jrEvent')) { // Get all past events $time = time(); $_s = array( "search" => array ( "event_date < {$time}" ), "limit" => 1000, 'exclude_jrProfile_keys' => true, 'exclude_jrProfile_quota_keys' => true ); $_rt = jrCore_db_search_items('jrEvent',$_s); if (isset($_rt) && is_array($_rt)) { // Delete them $ctr = 0; foreach ($_rt as $rt) { jrCore_db_delete_item('jrEvent',$rt['_item_id']); $ctr++; } jrCore_logger('INF',"{$ctr} past jrEvent items deleted"); } } return $_data; }



--
Paul Asher - JR Developer and System Import Specialist

updated by @paul: 02/17/14 09:50:26AM
MAD
MAD
@madc
10 years ago
600 posts
How the hell do you do that sh#$ so fast? :D


--
~ https://punkbandpromotions.com ~
Check us out for all your Punk/Alternative Music!
Check us out on Facebook:- https://facebook.com/PunkBandPromotion
paul
@paul
10 years ago
4,326 posts
MAD©:
How the hell do you do that sh#$ so fast? :D

Copy/Paste/Edit from other scraps of JR code ;-)


--
Paul Asher - JR Developer and System Import Specialist
MAD
MAD
@madc
10 years ago
600 posts
@MAD© Wishes he knew smarty better
Be still good for other members I think to have a cutoff system that they can set to how long they want to keep them for.
I can see why some members would want to bloat there site for SEO purposes but we aren't interested in that.


--
~ https://punkbandpromotions.com ~
Check us out for all your Punk/Alternative Music!
Check us out on Facebook:- https://facebook.com/PunkBandPromotion
MAD
MAD
@madc
10 years ago
600 posts
Ok I think I did it ok
I created a folder called prDeletePastEvents in the Modules folder and then added the include.php file and an empty index.php file ( no idea why ).

I pasted this in my include file

<?php

// make sure we are not being called directly 
defined('APP_DIR') or exit(); 

/** 
* meta 
*/ 
function prDeletePastEvents_meta() { 
$_tmp = array( 
'name' => 'Delete Past Events', 
'url' => 'deletepastevents', 
'version' => '1.0.0', 
'developer' => '@paul, ©' . strftime('%Y'), 
'description' => 'Listens for the "daily" event then deletes all jrEvent items that are past', 
'category' => 'PBP Custom Modules' 
); 
return $_tmp; 
} 

/** 
* init 
*/ 
function prDeletePastEvents_init() { 
jrCore_register_event_listener('jrCore','daily_maintenance','prDeletePastEvents_listener'); 

return true; 
} 

//--------------------------------------------------------- 
// EVENT LISTENERS 
//--------------------------------------------------------- 

/** 
* @param $_data array incoming data array 
* @param $_user array current user info 
* @param $_conf array Global config 
* @param $_args array additional info about the module 
* @param $event string Event Trigger name 
* @return array 
*/ 
function prDeletePastEvents_listener($_data, $_user, $_conf, $_args, $event) { 
// Is there a jrEvent module? 
if (jrCore_module_is_active('jrEvent')) { 
// Get all past events 
$time = time(); 
$_s = array( 
"search" => array ( 
"event_date < {$time}" 
), 
"limit" => 1000, 
'exclude_jrProfile_keys' => true, 
'exclude_jrProfile_quota_keys' => true 
); 
$_rt = jrCore_db_search_items('jrEvent',$_s); 
if (isset($_rt) && is_array($_rt)) { 
// Delete them 
$ctr = 0; 
foreach ($_rt as $rt) { 
jrCore_db_delete_item('jrEvent',$rt['_item_id']); 
$ctr++; 
} 
jrCore_logger('INF',"{$ctr} past jrEvent items deleted"); 
} 
} 
return $_data; 
} 

Ran integrity check, cleared caches etc
In this code, Is it going to run once a day? ( which is why I don't see any changes )
As it has the daily_maintenance code in there?

So by tomorrow server time after 12am they should be cleared?
Or am I missing something?


--
~ https://punkbandpromotions.com ~
Check us out for all your Punk/Alternative Music!
Check us out on Facebook:- https://facebook.com/PunkBandPromotion
paul
@paul
10 years ago
4,326 posts
Yeah - this will run once a day, after midnight.
Make the the module is enabled.
NOTE - This code is untested. I don't want to be responsible for something going wrong and all your events being deleted (or worst) !!!
Initially I'd debug it by commenting out the actual delete call and writing event info to the activity log, just to be sure that it will delete the correct events -

<?php

// make sure we are not being called directly
defined('APP_DIR') or exit();

/**
 * meta
 */
function prDeletePastEvents_meta(){
    $_tmp = array(
        'name' => 'Delete Past Events',
        'url' => 'deletepastevents',
        'version' => '1.0.0',
        'developer' => '@paul, ©' . strftime('%Y'),
        'description' => 'Listens for the "daily" event then deletes all jrEvent items that are past',
        'category' => 'PBP Custom Modules'
    );
    return $_tmp;
}

/**
 * init
 */
function prDeletePastEvents_init(){
    jrCore_register_event_listener('jrCore','daily_maintenance','prDeletePastEvents_listener');

    return true;
}

//---------------------------------------------------------
// EVENT LISTENERS
//---------------------------------------------------------

/**
 * @param $_data array incoming data array
 * @param $_user array current user info
 * @param $_conf array Global config
 * @param $_args array additional info about the module
 * @param $event string Event Trigger name
 * @return array
 */
function prDeletePastEvents_listener($_data, $_user, $_conf, $_args, $event)
{ // Is there a jrEvent module? if (jrCore_module_is_active('jrEvent')) { // Get all past events $time = time() - 86400; $_s = array( "search" => array ( "event_date < {$time}" ), "limit" => 1000, 'exclude_jrProfile_keys' => true, 'exclude_jrProfile_quota_keys' => true ); $_rt = jrCore_db_search_items('jrEvent',$_s); if (isset($_rt) && is_array($_rt)) { // Delete them $ctr = 0; foreach ($_rt as $rt) { $edate = date('d M Y',$rt['event_date']); jrCore_logger('INF',"Event {$edate} - {$rt['event_title']} will be deleted"); // jrCore_db_delete_item('jrEvent',$rt['_item_id']); $ctr++; } jrCore_logger('INF',"{$ctr} past jrEvent items deleted"); } } return $_data; }

Note also that I subtracted a day from the search time so that events in different time zones will not be deleted prematurely.


--
Paul Asher - JR Developer and System Import Specialist
MAD
MAD
@madc
10 years ago
600 posts
paul:
Initially I'd debug it by commenting out the actual delete call and writing event info to the activity log, just to be sure that it will delete the correct events -
//                jrCore_db_delete_item('jrEvent',$rt['_item_id']);
You already did in your code lol
We have a testing domain buddy so alls good
I will run it without the comments and see how it goes
Hopefully all good!!


--
~ https://punkbandpromotions.com ~
Check us out for all your Punk/Alternative Music!
Check us out on Facebook:- https://facebook.com/PunkBandPromotion
SteveX
SteveX
@ultrajam
10 years ago
2,584 posts
All good stuff!

But what happens when you promote your gigs online, people find it and link to the event page, tweet it etc and then you delete the content after the gig?
People will stop linking to your site if they realise they are going to have a bunch of dead links to remove the day after the gig.

I guess you'll be making a very interesting 404 Not Found page to go with this! ;)


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
MAD
MAD
@madc
10 years ago
600 posts
Yep, It will redirect to ONE page saying , Hmmmm.... Gig is done . Click here for current gigs?
The amount of GB's of image uploads etc that we have or are expecting in the events makes the server bloated with stuff we really don't need unless we get an amazon account with unlimited space....that aint gonna happen.
We are a promotion site not a storage holder for old stuff.
A Redirect page is the only option in that case or we redirect to the bands page.

We aren't myspace....did I say that out loud?

Also anyone that links to it should know ( From past experience ) that if it's over it is dead.
Not up to us to worry about the people linking in.

BTW I would probably change it to a month before it deletes.
Only prob is that they come down in date order so old ones show first.
Unless I move them daily the old ones will still show first which is annoying as that is hard coded in the core.
Should be showing UPCOMING events in desc order from todays date not old events that are done.


--
~ https://punkbandpromotions.com ~
Check us out for all your Punk/Alternative Music!
Check us out on Facebook:- https://facebook.com/PunkBandPromotion
SteveX
SteveX
@ultrajam
10 years ago
2,584 posts
Different strokes for different folks, whatever works for you.

I'd remove past events from the jrCore_list pages using search="$smarty.now < $event_date". Then adapt Pauls module to only remove the media from the past event, and make a smarty function to go on each event detail page which shows a "Gig is done . Click here for current gigs" notice. That way you keep all the links to your gigs live (including the internal links in your activity streams), save the server space, and have all the historical data of user activity in case you ever need to have your site valued.


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
MAD
MAD
@madc
10 years ago
600 posts
Thats a great idea @SteveX.
I will look into that shortly but I think thats the way we will go. Cheers for that :)

Just an update also, The module never cleared any info on my mirrored site that i can see.
Although it says 3 deleted and not sure why it's reading the year as 1969??

This is the log

18 Feb 2014 02:42:18AM xxx.xxx.xxx.xxx daily_maintenance completed
18 Feb 2014 02:42:18AM xxx.xxx.xxx.xxx [system]: deleted 2 trace items older than 7 days
18 Feb 2014 02:42:18AM xxx.xxx.xxx.xxx [system]: 3 past jrEvent items deleted
18 Feb 2014 02:42:18AM xxx.xxx.xxx.xxx [system]: Event 31 Dec 1969 - will be deleted
18 Feb 2014 02:42:18AM xxx.xxx.xxx.xxx [system]: Event 31 Dec 1969 - will be deleted
18 Feb 2014 02:42:18AM xxx.xxx.xxx.xxx [system]: Event 31 Dec 1969 - will be deleted
18 Feb 2014 02:42:18AM xxx.xxx.xxx.xxx [system]: successfully updated chart positions for 95 DataStore fields
18 Feb 2014 02:42:18AM xxx.xxx.xxx.xxx daily_maintenance started

I compared a before and after of the jrevents table in the database and they are identical so it looks like nothing got removed

All data still shows on Concert pages still as well as profile events.
And according to that it has deleted 3 yet there are 5 to delete right now dating from dec 2013 to 10th jan 2014
Compared another page I had open from yesterday and they are the same

You can see them here http://final.punkbp.com/concerts
I can't understand still why JR lists past events in the Upcoming events tab by default.
That couldn't be right is it?


--
~ https://punkbandpromotions.com ~
Check us out for all your Punk/Alternative Music!
Check us out on Facebook:- https://facebook.com/PunkBandPromotion
MAD
MAD
@madc
10 years ago
600 posts
Ok I tested with pulling a field into my home page
I am using this code

{jrCore_list module="jrEvent" search="event_date >= `$smarty.now`" order_by="event_date asc" limit=10}
Works great .

Now i went back to Nova skins concert.tpl file and it is has this code for upcoming concerts
{assign var="newclass" value="p_choice_active"}
{assign var="order_by" value="event_date asc"}

So the nova skin is using event_date asc for the value and not from todays date

How would I change that?
That would fix the problem
Tried adding this
    {assign var="order_by" value="event_date >= `$smarty.now` asc"}
Alls I get is this
error: invalid order direction received for event_date - must be one of: ASC, DESC, NUMERICAL_ASC, NUMERICAL_DESC, RANDOM


--
~ https://punkbandpromotions.com ~
Check us out for all your Punk/Alternative Music!
Check us out on Facebook:- https://facebook.com/PunkBandPromotion

updated by @madc: 03/03/14 06:46:12AM
brian
@brian
10 years ago
10,148 posts
If you are trying to restrict shows that have not passed (like in your home page) then you need to adjust the jrCore_list call in the concert.tpl file and add in your search condition - do don't need to do anything with the "order_by" value.

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
MAD
MAD
@madc
10 years ago
600 posts
Ok I worked it out
Had to remove the order by section in two places
{jrCore_list module="jrEvent" order_by=$order_by 

and replace it with this
{jrCore_list module="jrEvent" search="event_date >= `$smarty.now`"

All is working now.

Thought that would have been standard in a skin for upcoming concerts ? ( from todays date )
Should the Nova skin be updated at your end or is there a reason why you guys kept past concerts in the Upcoming Concerts section of the concert.tpl?

to fix if anyone else wants this capability, below is my edit of the bottom of the file

<div class="inner">
{if isset($_conf.jrPunkBP_require_images) && $_conf.jrPunkBP_require_images == 'on'}

    {if isset($_post._1) && strlen($_post._1) > 1}
        {jrCore_list module="jrEvent" order_by=$order_by search="event_location = `$_post._1`" template="concerts_row.tpl" require_image="event_image" pagebreak=$_conf.jrPunkBP_default_pagebreak page=$_post.p}
    {elseif isset($_post.option) && $_post.option == 'locations'}
        {jrCore_list module="jrEvent" order_by=$order_by group_by="event_location" template="concerts_locations.tpl" require_image="event_image" pagebreak="20" page=$_post.p}
    {else}
        {jrCore_list module="jrEvent" search="event_date >= `$smarty.now`" order_by="event_date asc" template="concerts_row.tpl" require_image="event_image" pagebreak=$_conf.jrPunkBP_default_pagebreak page=$_post.p}
    {/if}

{else}

    {if isset($_post._1) && strlen($_post._1) > 1}
        {jrCore_list module="jrEvent" order_by=$order_by search="event_location = `$_post._1`" template="concerts_row.tpl" pagebreak=$_conf.jrPunkBP_default_pagebreak page=$_post.p}
    {elseif isset($_post.option) && $_post.option == 'locations'}
        {jrCore_list module="jrEvent" order_by=$order_by group_by="event_location" template="concerts_locations.tpl" pagebreak="20" page=$_post.p}
    {else}
        {jrCore_list module="jrEvent" search="event_date >= `$smarty.now`" order_by="event_date asc" template="concerts_row.tpl" pagebreak=$_conf.jrPunkBP_default_pagebreak page=$_post.p}
    {/if}

{/if}

</div>

{jrCore_include template="footer.tpl"}

This can be closed now @brian. Thanks @paul and @SteveX for your help.
As I have said in other posts. Complete newbie but slowly getting there :)


--
~ https://punkbandpromotions.com ~
Check us out for all your Punk/Alternative Music!
Check us out on Facebook:- https://facebook.com/PunkBandPromotion
brian
@brian
10 years ago
10,148 posts
I think this is just a holdover from the conversion from the JR4 script - there was a setting in the skin config for "show past events" - that might need to just be added back in.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

updated by @brian: 03/03/14 08:21:36AM

Tags