2 part question for file editing and cron jobs

oh hell, i thought that insert code was a way to edit the existing post (something that’s really needed here).

Yes, your IF does not loop thru all of the filenames, it does sort-of, but, not correctly.
Let us know if the new loop works…

ok, i got it switched to the foreach loop and kinda cleaned it up some. One more question before i show off the code.

is there a way to put all this into a function, so i don’t have to type it all over and over again. We just signed a couple of more contracts with some other stores, so these are going to expand quite a bit.
[php]
$path = ‘/home/watunesc/public_html/venzodigital.com/admin/trends/itunes’;
$ReportFile = “/home/watunesc/public_html/venzodigital.com/admin/files/”.$file;
$companyTbl = ‘venzo_trends_sales’;
$fh = fopen($ReportFile, ‘r’);
$FullTextOfReport = fread($fh, filesize($ReportFile));
fclose($fh);
$FullTextReportWithoutTotals = substr($FullTextOfReport, 0, strpos($FullTextOfReport, ‘Total_Rows’));
copy($ReportFile, $path."/".$file);
$type = “itunes_trends”;
[/php]
well maybe not all of it, but maybe some of the longer pieces?

Also couldn’t get it to create that log, so i changed that over to a mysql table insert, 1 or 0 depending on if it was good or bad.

Well, if you mean you will be repeating the code you posted over and over, sure.
Put the path, reportfile, companytbl and type into a database table.
Then, loop thru your function pulling these from the database.

Or, you could read all of the above from the database table and load into an array
and use the array to loop thru. Either is good, but, loading into an array keeps the
database connection open less time while the files are processed.

Is that what you are asking? If so, go for it… If not ask again…

sounds simple enough, at least on paper anyways :slight_smile:

this is what i came up with:
[php]
function info($case) {
$qry = mysql_query(“SELECT * FROM venzo_files WHERE name = ‘$case’”);
$s = mysql_fetch_assoc($qry);

$path = $s['path'];
$ReportFile = "/home/watunesc/public_html/venzodigital.com/admin/files/".$file;
$companyTbl = $s['table'];
$type = $s['type'];

$fh = fopen($ReportFile, 'r');
$FullTextOfReport = fread($fh, filesize($ReportFile));
fclose($fh);
$FullTextReportWithoutTotals = substr($FullTextOfReport, 0, strpos($FullTextOfReport, 'Total_Rows'));
copy($ReportFile, $path."/".$file);

}

$filen = basename($file);

//inside foreach loop

if(left($filen, 12) == 'S_W_80045583') {
	info('S_W_80045583');
} elseif(left($filen, 12) == 'S_W_85409067') {
	info('S_W_85409067');
} elseif(left($filen, 8) == '80045583') {
	info('80045583');
} elseif(left($filen, 8) == '85409067') {
	info('85409067'):
} else {
	mysql_query("INSERT INTO venzo_insert_logs VALUES('', '{$type}', '{$file}', 3, NOW())");
}

[/php]

I just wish there was a way that i didn’t have to hard code the file names. I’m not sure i’ll be able to do that with the other stores. All of those are for itunes.

Well, if the new stores have a similar format, you could figure out a coding sequence for them.
DO you know what the account filename for the are going to be yet?

Also, This section:

if(left($filen, 12) == ‘S_W_80045583’) {
info(‘S_W_80045583’);
} elseif(left($filen, 12) == ‘S_W_85409067’) {
info(‘S_W_85409067’);
} elseif(left($filen, 8) == ‘80045583’) {
info(‘80045583’);
} elseif(left($filen, 8) == ‘85409067’) {
info(‘85409067’):

could be condensed… If you already have these in the NAME field in the database you could use a different format and use it inside the query, something like this…
if left($filen,1)=“S” {
$case=left($filen,12);
}else{
$case=left($filen,8);
}
Then, when you query the database, if it is not found, (0 records) then ignore that file…

What else is left?

Only thing left (that i know of) is to get it log properly. right now, its not doing the query that i put in place of the import log. Might have to rework the entire script abit.

Well, we wont mark it solved as yet, ask any questions… I am sure someone will help…

I’m not worried about it. The script is importing the data, which is what’s important. all the sales reports are in with no issues. the next test will hopefully be tomorrow (monday) with the trends for last week. after that, i’ll upload the new version and see how that goes.

Okay, we will consider this thread closed. If you have other problems, please create a new post.

I am very glad you got this working and I am sure having this in the archives will help others in the future.
Actually I am new to “CRON” jobs, but, have learned some in helping you with the PHP… Glad it is working!

yea me to, took some research to figure out why i was getting the errors i was getting. Didn’t realize i had to tell it that i was using a php script. This is what i had to use

/usr/bin/php -q /home/watunesc/public_html/venzodigital.com/admin/import_files_exp.php

apparently web servers aren’t all that intelligent :slight_smile:

Web servers are just programmed by programmers… Some make it easier than others.
For instance, I have spent two days trying to fix a problem and it was all due to a missing comma! YIKES!

Glad you are up and running. I will mark this one SOLVED. Any other questions, create a new thread post!

Sponsor our Newsletter | Privacy Policy | Terms of Service