codecreative Posted September 27, 2013 Share Posted September 27, 2013 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, 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. 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... If it is great output "deleting property post" in the log and display value property_post being deleted 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); } } } Quote Link to comment https://forums.phpfreaks.com/topic/282473-iteration-to-check-if-xlm-data-exists-in-db/ Share on other sites More sharing options...
Ch0cu3r Posted September 27, 2013 Share Posted September 27, 2013 (edited) 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 September 27, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/282473-iteration-to-check-if-xlm-data-exists-in-db/#findComment-1451395 Share on other sites More sharing options...
codecreative Posted September 27, 2013 Author Share Posted September 27, 2013 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; } } } Quote Link to comment https://forums.phpfreaks.com/topic/282473-iteration-to-check-if-xlm-data-exists-in-db/#findComment-1451433 Share on other sites More sharing options...
codecreative Posted September 27, 2013 Author Share Posted September 27, 2013 Looking at the php function json_decode I read this line. Returns the value encoded in json in appropriate PHP type. Does that mean php would actually know to decode this into an array type? Quote Link to comment https://forums.phpfreaks.com/topic/282473-iteration-to-check-if-xlm-data-exists-in-db/#findComment-1451434 Share on other sites More sharing options...
codecreative Posted September 27, 2013 Author Share Posted September 27, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/282473-iteration-to-check-if-xlm-data-exists-in-db/#findComment-1451436 Share on other sites More sharing options...
codecreative Posted September 27, 2013 Author Share Posted September 27, 2013 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'; Quote Link to comment https://forums.phpfreaks.com/topic/282473-iteration-to-check-if-xlm-data-exists-in-db/#findComment-1451440 Share on other sites More sharing options...
Ch0cu3r Posted September 27, 2013 Share Posted September 27, 2013 (edited) 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 September 27, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/282473-iteration-to-check-if-xlm-data-exists-in-db/#findComment-1451446 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.