/** * Gives status messages about the difference between 2 array elements * correponding to a collection entry in the database * * @return array of message with their types */ public static function compareEntries($entries, $type, $file, $where, $autoApply = false) { $msg = array(); $arrayFromDataFolder = PHDB::getArrayFromDataFolder($file, $where); if (isset($entries[$type]["_id"])) { unset($entries[$type]["_id"]); } //testing existence if (!isset($entries[$type])) { array_push($msg, array("type" => "error", "msg" => "no {$type} in DB")); if ($autoApply) { PHDB::insert($file, $arrayFromDataFolder); array_push($msg, array("type" => "action", "msg" => "new {$type} inserted DB")); array_push($msg, array("type" => "ok", "msg" => "{$type} entry has been updated in Database, <br/>")); } } else { if ($diff = ArrayHelper::array_diff_assoc_recursive($arrayFromDataFolder, $entries[$type])) { array_push($msg, array("type" => "error", "msg" => "{$type} entry isn't up to date , some data has been 'added' to current content <br/>")); //var_dump($arrayFromDataFolder); //var_dump($entries[$type]); var_dump($diff); if (!empty($diff) && $autoApply) { PHDB::remove($file, array($where["key"] => $where["value"])); array_push($msg, array("type" => "action", "msg" => "old {$type} removed DB")); PHDB::insert($file, $arrayFromDataFolder); array_push($msg, array("type" => "action", "msg" => "new {$type} inserted DB")); array_push($msg, array("type" => "ok", "msg" => "{$type} entry has been updated in Database, <br/>")); } } else { if ($diff = ArrayHelper::array_diff_assoc_recursive($entries[$type], $arrayFromDataFolder)) { array_push($msg, array("type" => "error", "msg" => "{$type} entry isn't up to date , some data has been 'removed' from current content <br/>")); //var_dump($arrayFromDataFolder); //var_dump($entries[$type]); var_dump($diff); if (!empty($diff) && $autoApply) { PHDB::remove($file, array($where["key"] => $where["value"])); array_push($msg, array("type" => "action", "msg" => "old {$type} removed DB")); PHDB::insert($file, $arrayFromDataFolder); array_push($msg, array("type" => "action", "msg" => "new {$type} inserted DB")); array_push($msg, array("type" => "ok", "msg" => "{$type} entry has been updated in Database, <br/>")); } } else { array_push($msg, array("type" => "ok", "msg" => "nothing to update on {$type}")); } } } return $msg; }