<?php session_save_path('/tmp'); ini_set('memory_limit', -1); set_time_limit(0); require "../header.php"; if (!isCLI()) { print "Must be run from the command line."; exit; } // Turn off EngineAPI template engine $engine->obCallback = FALSE; $forms = forms::getForms(NULL); $dupeConfirm = array(TRUE => 0, FALSE => 0); foreach ($forms as $form) { print "Form: " . $form['title'] . "\n"; $objects = objects::getAllObjectsForForm($form['ID']); foreach ($objects as $object) { unset(mfcs::$engine->cleanPost['MYSQL']); $return = duplicates::updateDupeTable($form['ID'], $object['ID'], $object['data']); $dupeConfirm[$return]++; } } print "\n\n"; var_dump($dupeConfirm); print "Done.\n\n";
public static function update($objectID, $formID, $data, $metadata, $parentID = 0, $modifiedTime = NULL) { if (!is_array($data)) { errorHandle::newError(__METHOD__ . "() - : data is not array", errorHandle::DEBUG); return FALSE; } // Get the current Form if (($form = forms::get($formID)) === FALSE) { errorHandle::newError(__METHOD__ . "() - retrieving form by formID", errorHandle::DEBUG); return FALSE; } // the form is an object form, make sure that it has an ID field defined. if (($idnoInfo = forms::getFormIDInfo($formID)) === FALSE) { errorHandle::newError(__METHOD__ . "() - no IDNO field for object form.", errorHandle::DEBUG); return FALSE; } // begin transactions $result = mfcs::$engine->openDB->transBegin("objects"); if ($result !== TRUE) { errorHandle::newError(__METHOD__ . "() - unable to start database transactions", errorHandle::DEBUG); return FALSE; } // place old version into revision control // excluding metadata objects if ($metadata == 0) { $rcs = revisions::create(); $return = $rcs->insertRevision($objectID); if ($return !== TRUE) { mfcs::$engine->openDB->transRollback(); mfcs::$engine->openDB->transEnd(); errorHandle::newError(__METHOD__ . "() - unable to insert revisions", errorHandle::DEBUG); return FALSE; } } // insert new version $sql = sprintf("UPDATE `objects` SET `parentID`='%s', `data`='%s', `formID`='%s', `metadata`='%s', `modifiedTime`='%s', `modifiedBy`='%s' WHERE `ID`='%s'", isset(mfcs::$engine->cleanPost['MYSQL']['parentID']) ? mfcs::$engine->cleanPost['MYSQL']['parentID'] : mfcs::$engine->openDB->escape($parentID), encodeFields($data), mfcs::$engine->openDB->escape($formID), mfcs::$engine->openDB->escape($metadata), isnull($modifiedTime) ? time() : $modifiedTime, mfcs::$engine->openDB->escape(users::user('ID')), mfcs::$engine->openDB->escape($objectID)); $sqlResult = mfcs::$engine->openDB->query($sql); if (!$sqlResult['result']) { mfcs::$engine->openDB->transRollback(); mfcs::$engine->openDB->transEnd(); errorHandle::newError(__METHOD__ . "() - " . $sql . " -- " . $sqlResult['error'], errorHandle::DEBUG); return FALSE; } // Insert into the new data table if (self::insertObjectData($objectID, $data, $formID) === FALSE) { mfcs::$engine->openDB->transRollback(); mfcs::$engine->openDB->transEnd(); errorHandle::newError(__METHOD__ . "() - inserting objects", errorHandle::DEBUG); return FALSE; } // Update duplicate matching table if (duplicates::updateDupeTable($formID, $objectID, $data) === FALSE) { mfcs::$engine->openDB->transRollback(); mfcs::$engine->openDB->transEnd(); errorHandle::newError(__METHOD__ . "() - updating dupe matching", errorHandle::DEBUG); return FALSE; } // if it is an object form (not a metadata form) // do the IDNO stuff // We only have to do this if the IDNO is managed by the user if ($form['metadata'] == "0" && $idnoInfo['managedBy'] != "system") { // the form is an object form, make sure that it has an ID field defined. if (($idnoInfo = forms::getFormIDInfo($formID)) === FALSE) { errorHandle::newError(__METHOD__ . "() - no IDNO field for object form.", errorHandle::DEBUG); return FALSE; } $idno = isset(mfcs::$engine->cleanPost['MYSQL']['idno']) && !isempty(mfcs::$engine->cleanPost['MYSQL']['idno']) ? mfcs::$engine->cleanPost['MYSQL']['idno'] : self::getIDNOForObjectID($objectID); if ($idno === FALSE || isempty($idno)) { mfcs::$engine->openDB->transRollback(); mfcs::$engine->openDB->transEnd(); return FALSE; } if (!self::updateIDNO($objectID, $idno)) { mfcs::$engine->openDB->transRollback(); mfcs::$engine->openDB->transEnd(); errorHandle::newError(__METHOD__ . "() - updating the IDNO: " . $sqlResult['error'], errorHandle::DEBUG); return FALSE; } } // end transactions mfcs::$engine->openDB->transCommit(); mfcs::$engine->openDB->transEnd(); return TRUE; }
public static function isDupe($formID, $field, $value, $objectID = NULL) { return duplicates::isDupe($formID, $field, $value, $objectID); }
include "../public_html/includes/functions.php"; include "../public_html/includes/validator.php"; $objects = objects::get(); // Begin the transaction if (mfcs::$engine->openDB->transBegin("objects") !== TRUE) { print __METHOD__ . "() - unable to start database transactions"; exit; } foreach ($objects as $object) { // only rebuild the objects if ($object['metadata'] != '0') { continue; } // Build cleanPost // @TODO this should be stripped when updateDupeTable is fixed to not require cleanPost // Reset cleanPost mfcs::$engine->cleanPost['MYSQL'] = array(); mfcs::$engine->cleanPost['HTML'] = array(); mfcs::$engine->cleanPost['RAW'] = array(); foreach ($object['data'] as $name => $raw) { http::setPost($name, $raw); } if (duplicates::updateDupeTable($object['formID'], $object['ID'], $object['data']) === FALSE) { mfcs::$engine->openDB->transRollback(); mfcs::$engine->openDB->transEnd(); print __METHOD__ . "() - updating dupe matching"; exit; } } mfcs::$engine->openDB->transCommit(); mfcs::$engine->openDB->transEnd();