/** * Delete an entry from the organization table using the id */ public function run() { //TODO SBAR : refactor : not use $result = array("result" => false, "msg" => Yii::t("common", "Uncorrect request")); if (Yii::app()->session["userId"]) { $account = Organization::getById($_POST["id"]); if ($account && Yii::app()->session["userEmail"] == $account['ph:owner']) { PHDB::remove(Organization::COLLECTION, array("_id" => new MongoId($_POST["id"]))); //temporary for dev //TODO : Remove the association from all Ci accounts PHDB::update(PHType::TYPE_CITOYEN, array("_id" => new MongoId(Yii::app()->session["userId"])), array('$pull' => array("associations" => new MongoId($_POST["id"])))); $result = array("result" => true, "msg" => Yii::t("common", "Data saved")); } } Rest::json($result); }
public static function processEntry($params) { //echo "<br/>processing entry ".$params["type"].", id".$params["_id"]; if ($params["type"] == self::TYPE_MAIL) { $res = self::processMail($params); //echo "<br/>sendmail : ".$params["subject"].", <br/>result :".((is_array($res)) ? $res["msg"] : $res); } if (!is_array($res) && $res) { //echo "<br/>processing entry ".$params["type"]; PHDB::remove(self::COLLECTION, array("_id" => new MongoId($params["_id"]))); } else { //something went wrong with the process $msg = is_array($res) && isset($res["msg"]) ? $res["msg"] : ""; PHDB::update(self::COLLECTION, array("_id" => new MongoId($params["_id"])), array('$set' => array("status" => self::STATUS_FAIL, "executedTS" => new MongoDate(), "errorMsg" => $msg))); //TODO : add notification to system admin //explaining the fail } }
/** * 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; }
public static function removeProject($projectId, $userId) { $type = Person::COLLECTION; if (!Authorisation::canEditItem($userId, self::COLLECTION, $projectId)) { throw new CTKException("You can't remove this project : you are not admin of it"); } //0. Remove the links Link::disconnect($userId, $type, $projectId, PHType::TYPE_PROJECTS, $userId, "projects"); //1. Remove project's sheet corresponding to $projectId _id PHDB::remove(self::COLLECTION, array("_id" => new MongoId($projectId))); return array("result" => true, "msg" => "The project has been removed with success", "projectid" => $projectId); }
public static function removeData($collection, $type, $isDummy, $linkAllToActiveUser) { $error = null; if ($isDummy) { $rows = PHDB::find($collection, array("dummyData" => $type)); } $info = array("collection" => $collection); $userId = Yii::app()->session["userId"]; foreach ($rows as $key => $value) { if ($linkAllToActiveUser) { if ($collection == PHType::TYPE_CITOYEN) { PHDB::update(PHType::TYPE_CITOYEN, array("_id" => new MongoId($userId)), array('$unset' => array(Link::person2person . "." . $key => 1))); } elseif ($collection == PHType::TYPE_ORGANIZATIONS) { PHDB::update(PHType::TYPE_CITOYEN, array("_id" => new MongoId($userId)), array('$unset' => array(Link::person2organization . "." . $key => 1))); } elseif ($collection == PHType::TYPE_EVENTS) { PHDB::update(PHType::TYPE_CITOYEN, array("_id" => new MongoId($userId)), array('$unset' => array(Link::person2events . "." . $key => 1))); } elseif ($collection == PHType::TYPE_PROJECTS) { PHDB::update(PHType::TYPE_CITOYEN, array("_id" => new MongoId($userId)), array('$unset' => array(Link::person2projects . "." . $key => 1))); } } PHDB::remove($collection, array("_id" => new MongoId($key))); } return array("count" => count($rows)); }
/** * Remove a job with his jobId * @param String $jobId * @param String $userId * @return array of the result (result => bool, msg => String) */ public static function removeJob($jobId, $userId) { if (!Authorisation::isJobAdmin($jobId, $userId)) { throw new CTKException(Yii::t("job", "Can not remove the job : you are not authorized to update that job offer !")); } //update the job PHDB::remove(Job::COLLECTION, array("_id" => new MongoId($jobId))); return array("result" => true, "msg" => Yii::t("job", "Your job offer has been deleted with success")); }
/** * remove a document by id * @return */ public static function removeDocumentById($id) { return PHDB::remove(self::COLLECTION, array("_id" => new MongoId($id))); }
public static function delete($eventId, $userId) { if (!Authorisation::isEventAdmin($eventId, $userId)) { throw new CTKException("Can not delete the event : you are not authorized to delete that event!"); } $res = Link::removeEventLinks($eventId); if ($res["ok"] == 1) { $res = PHDB::remove(self::COLLECTION, array("_id" => new MongoId($eventId))); } return array("result" => true, "msg" => "Votre evenement est supprimé.", "id" => $eventId); }