/** * Disables old revisions in user database, create a copy of content records in user database then acquire lock on Delivery * @param {int} $UID The UID of the edited Delivery * @param {int} $user The user that is editing the Delivery * @return {bool} returns true on success false otherwise */ public static function begin_editing_Delivery($UID, $user) { // acquire lock copy data records of the Delivery from the content database into user database // get selected Delivery $curr_Delivery = Delivery::get_Delivery_by_UID($UID); if ($curr_Delivery == null) { debugLog::log("<i>[delivery.php:begin_editing_Delivery]</i> Could not find Delivery of the base (" . $UID . ") in content"); return false; } // try to acquire lock on the Delivery if (Lock::acquire_lock($UID, 'DELIVERY_BASE', $user) == false) { debugLog::log("<i>[delivery.php:begin_editing_Delivery]</i> Could not acquire lock on Delivery (" . $UID . "), check whether the Delivery is locked by other users"); return false; } // disable all Delivery information Delivery::disable_all_Delivery_info($UID, 'user'); // copy Delivery from content database into user database $dbObj = new dbAPI(); $where_sttmnt = ' WHERE UID = ' . $UID . ' AND ENABLED = 1 '; // get columns names $columns_names = $dbObj->db_get_columns_names($dbObj->db_get_usersDB(), "DELIVERY_BASE", true); // remove primary key (auto-increment) column (id) $columns_names = str_replace("id,", "", $columns_names); // copy record from content to user $query = "INSERT INTO " . $dbObj->db_get_usersDB() . ".DELIVERY_BASE (" . $columns_names . ") SELECT " . $columns_names . " FROM " . $dbObj->db_get_contentDB() . ".Delivery_BASE " . $where_sttmnt . ""; $dbObj->run_query('', $query); // get front Delivery table name $front_table_name = Delivery::get_front_table_name($curr_Delivery["FRONT_TYPE"]); if ($front_table_name == null) { debugLog::log("<i>[delivery.php:begin_editing_Delivery]</i> Could not find front Delivery table name (" . $UID . ")"); // roll back option here return false; } // get columns names $columns_names = $dbObj->db_get_columns_names($dbObj->db_get_usersDB(), $front_table_name, true); // remove primary key (auto-increment) column (id) $columns_names = str_replace("id,", "", $columns_names); // copy front record from content to user $query = "INSERT INTO " . $dbObj->db_get_usersDB() . "." . $front_table_name . " (" . $columns_names . ") SELECT " . $columns_names . " FROM " . $dbObj->db_get_contentDB() . "." . $front_table_name . " " . $where_sttmnt . ""; $dbObj->run_query('', $query); // loop over links and copy records from content to user $links_tables_names = Delivery::get_relations_tables_names(); for ($i = 0; $i < count($links_tables_names); $i++) { // prepare where statement if ($links_tables_names[$i] == 'R_LD2D') { $where_sttmnt = ' (PARENT_ID = ' . $UID . ' OR CHILD_ID = ' . $UID . ') '; } else { $where_sttmnt = ' (DELIVERY_BASE_ID = ' . $UID . ') '; } // get columns names $columns_names = $dbObj->db_get_columns_names($dbObj->db_get_usersDB(), $links_tables_names[$i], true); // remove primary key (auto-increment) column (id) $columns_names = str_replace("id,", "", $columns_names); // get all relevant relations $query = "SELECT id FROM " . $links_tables_names[$i] . " where " . $where_sttmnt . " AND ENABLED = '1'"; $relations = $dbObj->db_select_query($dbObj->db_get_contentDB(), $query); // loop over all records and insert them for ($j = 0; $j < count($relations); $j++) { $where_sttmnt = ' id =' . $relations[$j]["id"] . ' '; $query = "INSERT INTO " . $dbObj->db_get_usersDB() . "." . $links_tables_names[$i] . " (" . $columns_names . ") SELECT " . $columns_names . " FROM " . $dbObj->db_get_contentDB() . "." . $links_tables_names[$i] . " where " . $where_sttmnt . ""; $dbObj->run_query('', $query); } } return true; }