Auto delete

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
User avatar
TandyServices
Posts: 15
Joined: 2015-12-07 22:59
Location: Largo, Florida
Contact:

Auto delete

Post by TandyServices » 2015-12-08 00:33

Hello all,
Hope someone can help me out here. I am new to AppGini as well as database.
I am building a Load Board for trucking.
I have 4 different tables that all have date fields in them. What I need to figure out is after that date(say midnight) to have those records auto delete. But I would like to have a log of all that was in those tables.
The reason I need this is because old records will not help. If a truck gets loaded that day. And the owner of that record does not come back in to delete it. and say I have thousands of members putting there records in every day. That page will never end so I need the whole line to be deleted off the page.
But in the same time I might need to go back and find an old record. So if I can save it all to a log file on the server, I can still go back and see what went on for lets say ID key 100 or 125..

Any help would be great if this can even be done with AppGini


Thank You
James

User avatar
a.gneady
Site Admin
Posts: 1354
Joined: 2012-09-27 14:46
Contact:

Re: Auto delete

Post by a.gneady » 2015-12-08 19:41

Hmm ... instead of deleting old records and keeping a copy of them in a log, how about applying a default filter to the table to display only today's records? And if you want to view older records, you can clear the filter. Here is how you can apply a default filter to a table.
:idea: AppGini plugins to add more power to your apps:

User avatar
TandyServices
Posts: 15
Joined: 2015-12-07 22:59
Location: Largo, Florida
Contact:

Re: Auto delete

Post by TandyServices » 2015-12-08 20:35

Ok. Then how would I write that out? Plus that would still over crowd the database if there are thousands of records. I would still need to add them to a file for later use, then prune them off the database so the database does not get slow..

User avatar
a.gneady
Site Admin
Posts: 1354
Joined: 2012-09-27 14:46
Contact:

Re: Auto delete

Post by a.gneady » 2015-12-09 20:19

Assuming the date field in your records is the third field in the table for example, the command to add to the hook (as explained in the above link) would look like this:

Code: Select all

addFilter(1, 'and', 3, 'equal-to', date('m/d/Y'));
This assumes your date format is month/day/year ... If you use another format, for example day.month.year, the command would look like:

Code: Select all

addFilter(1, 'and', 3, 'equal-to', date('d.m.Y'));
Plus that would still over crowd the database if there are thousands of records
MySQL is designed to handle millions of records efficiently. Moreover, you can add an index on the date field and this would make it very fast to display results when using the above filter. I see no reason to be worried about this unless you have very limited space on your server, which would make it unpractical to consider a log file as well.
:idea: AppGini plugins to add more power to your apps:

User avatar
TandyServices
Posts: 15
Joined: 2015-12-07 22:59
Location: Largo, Florida
Contact:

Re: Auto delete

Post by TandyServices » 2015-12-09 21:38

It does not work for me.. My field is the second one. The first one is the ID then pickup date. Here is my first few line to make sure it is right and it is in my hooks folder and file is loads.php

<?php
// For help on using hooks, please refer to http://bigprof.com/appgini/help/working ... tion/hooks

function loads_init(&$options, $memberInfo, &$args){
if(!$_POST['FilterField'][1] && !$_GET['FilterField'][1]){
addFilter(1, 'and', 2, 'less-than-or-equal-to', date('m/d/Y'));
}

return TRUE;
}

function loads_header($contentType, $memberInfo, &$args){
$header='';

switch($contentType){
case 'tableview':
$header='';
break;

case 'detailview':
$header='';
break;

User avatar
a.gneady
Site Admin
Posts: 1354
Joined: 2012-09-27 14:46
Contact:

Re: Auto delete

Post by a.gneady » 2015-12-10 21:31

What happens when you use this code?
Since you are using 'less-than-or-equal-to', the filter you defined would display records of today and all older ones. Is that what you need?
:idea: AppGini plugins to add more power to your apps:

User avatar
TandyServices
Posts: 15
Joined: 2015-12-07 22:59
Location: Largo, Florida
Contact:

Re: Auto delete

Post by TandyServices » 2015-12-10 21:34

No.. I had your way as well.. I just changed it to see if anything happens.. nothing happens at all, in any way. That is why I think I did not put the code in the right spot..

User avatar
a.gneady
Site Admin
Posts: 1354
Joined: 2012-09-27 14:46
Contact:

Re: Auto delete

Post by a.gneady » 2015-12-14 04:25

By "nothing happens at all" do you mean all data is displayed without any filtering, or nothing is displayed? If it is the former (that is, all data is displayed), try clicking the 'Filter' button to open the filters page, and see if any filters are defined.
:idea: AppGini plugins to add more power to your apps:

User avatar
TandyServices
Posts: 15
Joined: 2015-12-07 22:59
Location: Largo, Florida
Contact:

Re: Auto delete

Post by TandyServices » 2015-12-14 04:50

The page turn blank(white screen).. I took that code out and then I went into the filters on the page and added
PickUp Date then Equal to then date('m/d/Y')
That worked. But I can't not get the code in the hooks to work..

Here is what I have in there:

function loads_init(&$options, $memberInfo, &$args){
if(!$_POST['FilterField'][1] && !$_GET['FilterField'][2]){
addFilter(1, 'and', 3, 'equal-to', date('m/d/Y'));

return TRUE;

User avatar
a.gneady
Site Admin
Posts: 1354
Joined: 2012-09-27 14:46
Contact:

Re: Auto delete

Post by a.gneady » 2015-12-15 10:23

This seems to be due to a missing closing } -- line 4 below:

Code: Select all

function loads_init(&$options, $memberInfo, &$args){
    if(!$_POST['FilterField'][1] && !$_GET['FilterField'][2]){
        addFilter(1, 'and', 3, 'equal-to', date('m/d/Y'));
    }
    return TRUE;
}
:idea: AppGini plugins to add more power to your apps:

User avatar
TandyServices
Posts: 15
Joined: 2015-12-07 22:59
Location: Largo, Florida
Contact:

Re: Auto delete

Post by TandyServices » 2015-12-16 10:49

Ok that work but here is the way it works that I needed it.. Only today and days to come show.. yesterday and everything else does not show:

function loads_init(&$options, $memberInfo, &$args){
if(!$_POST['FilterField'][1] && !$_GET['FilterField'][1]){
addFilter(1, 'and', 3, 'greater-than-or-equal-to', date('m/d/Y'));
}

return TRUE;
}

Post Reply