Jump to content

iteration to check if xlm data exists in db


codecreative

Recommended Posts

Hi

 

I have a parser importing xml data, in this scenario it is properties for a property site.

 

If a property isn't included in the latest xml document uploaded then when it is parsed, the parser should remove the property entry from the database.

 

So someone can in theory delete a property. I have the following segment of code performing this, but to me I can't see how it is intelligently deleting properties. I can't see where the comparison is of what we have in the xml vs what we have in the database.

 

Correct me if I am wrong, but what I can see is it saying is,

 

  1. If the a variable dump_file_current_content is not false, log "Checking for properties that needs to be deleted" which is just providing some log output for feedback on what is going on.
  2. Then property ref as the key and property post as the value, to be assigned to dump_file_current_content, for each item check if dump_file_content (which is an array) of key property ref is set...
  3. If it is great output "deleting property post" in the log and display value property_post being deleted
  4. Then initiate the wordpress built in fuction to delete the post $property_post

Where is the condition that is "checking" for properties to be deleted? This just appears to me to delete all properties that have a property reference key value assigned

if(false !== $dump_file_current_content){
			$this->log('Chencking for properties that needs to be deleted');
			foreach ($dump_file_current_content as $property_ref => $property_post){
				if(!isset($dump_file_content[$property_ref])){
					$this->log('deleting property post #' . $property_post);
					wp_delete_post($property_post, true);
				}
			}
		}
Link to comment
Share on other sites

The comparison is happening here

if(!isset($dump_file_content[$property_ref])){

I'm guessing somewhere else in the script it is loading up the current data from the database into $dump_file_current_content array, and the new xml data into the $dump_file_content array.

 

The above line is checking if the database data is still in the xml data. If it isn't then it'll delete the property from the database.

Edited by Ch0cu3r
Link to comment
Share on other sites

Ah okay I sort of understand. I've look else where in the file and this is the segment of code that assigns the value of dump_file_content, it looks to me like the array doesn't contain the data from the database but the data from the xml file, is that correct? From looking at this

		if(file_exists($dump_file_name)){
			$_temp_content = file_get_contents($dump_file_name);
			if(!empty($_temp_content)){
				$_temp_content = json_decode($_temp_content, true);
				if(null !== $_temp_content){
					$dump_file_current_content = $_temp_content;
				}
			}
		}
Link to comment
Share on other sites

It just seems the wrong way around to me.

 

Lets say we have 3 properties in the database, prop1, prop2, and pro3 and in our xml file we have prop1 and prop2

 

I understand saying if prop1 isn't in the xml file then delete it from the database. So to me it should be iterateing through a data array containing the contents of the db not the xml file. Because in actual fact all content of the xml should be in the database. 

Link to comment
Share on other sites

My bad. I forgot the following line, I inspected the "dump" file and here is the data, clearly dump files are exports of data from databases I should of known, which must be in the json format which is why later json_decode is used. 

 

{"1111_17":2972,"1111_29":2974,"1111_44":2976}

 

Also I saw the use of md5, I thought that was for security to hashing sensitive information like passwords not too sure why it is being used when assigning this data to the $dump_file_name variable

$dump_file_name = $this->blmConfig['archive_path'] . DS . md5($file_name) . '.dump';
Link to comment
Share on other sites

md5 can be used for a whole range of things, passwords being one of the main uses but is being phased out for better password encryption methods.

 

md5 in the line you posted is being used to obfuscate the file name I guess, making it harder for hackers to guess the name of the dump file for instance.

Edited by Ch0cu3r
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.