From 9c9e4d3136bf07dd7252e670c9c473c1fd269869 Mon Sep 17 00:00:00 2001
From: Alex Orluc <alex.orluc@maarch.org>
Date: Fri, 30 Jan 2015 13:12:31 +0000
Subject: [PATCH] FEAT #1693 add function advanced_reactivate

---
 .../core/class/ObjectControlerAbstract.php    | 41 +++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/core/trunk/core/class/ObjectControlerAbstract.php b/core/trunk/core/class/ObjectControlerAbstract.php
index 65d5a917c35..ed9f655b907 100644
--- a/core/trunk/core/class/ObjectControlerAbstract.php
+++ b/core/trunk/core/class/ObjectControlerAbstract.php
@@ -418,6 +418,47 @@ abstract class ObjectControler
         return $result;
     }
 
+    /**
+     * Reactivate given object from given table, according with
+     * given table id name.
+     * Return true if succeeded.
+     * @param Any $object
+     * @return boolean
+     */
+    protected function advanced_reactivate($object)
+    {
+        if (!isset($object)) {
+            return false;
+        }
+        $table_name = get_class($object);
+        $table_id = $table_name . '_id';
+
+        if (isset(self::$specific_id) && !empty(self::$specific_id)) {
+            $table_id = self::$specific_id;
+        }
+        self::$db = new dbquery();
+        self::$db->connect();
+        if (in_array($table_id, self::$foolish_ids) ){
+             $query = "update $table_name set status = 'OK' where $table_id='"
+                    . $object->$table_id . "'";
+        } else {
+            $query="update $table_name set status = 'OK' where $table_id=".$object->$table_id;
+        }
+        try{
+            if(_DEBUG){
+                echo "enable: $query // ";
+            }
+            self::$db->query($query);
+            $result = true;
+        } catch (Exception $e) {
+            echo 'Impossible to enable object with id=' . $object->$table_id
+                . ' // ';
+            $result = false;
+        }
+        self::$db->disconnect();
+        return $result;
+    }
+
     /**
      * Disable given object from given table, according with
      * given table id name.
-- 
GitLab