public function deleteRecord() { // Create a pending change WT_DB::prepare("INSERT INTO `##change` (gedcom_id, xref, old_gedcom, new_gedcom, user_id) VALUES (?, ?, ?, '', ?)")->execute(array($this->gedcom_id, $this->xref, $this->getGedcom(), Auth::id())); // Accept this pending change if (Auth::user()->getSetting('auto_accept')) { accept_all_changes($this->xref, $this->gedcom_id); } // Clear the cache self::$gedcom_record_cache = null; self::$pending_record_cache = null; Log::addEditLog('Delete: ' . static::RECORD_TYPE . ' ' . $this->xref); }
function accept_all_changes($xref, $ged_id) { $changes = WT_DB::prepare("SELECT change_id, gedcom_name, old_gedcom, new_gedcom" . " FROM `##change` c" . " JOIN `##gedcom` g USING (gedcom_id)" . " WHERE c.status='pending' AND xref=? AND gedcom_id=?" . " ORDER BY change_id")->execute(array($xref, $ged_id))->fetchAll(); foreach ($changes as $change) { if (empty($change->new_gedcom)) { // delete update_record($change->old_gedcom, $ged_id, true); } else { // add/update update_record($change->new_gedcom, $ged_id, false); } WT_DB::prepare("UPDATE `##change`" . " SET status='accepted'" . " WHERE status='pending' AND xref=? AND gedcom_id=?")->execute(array($xref, $ged_id)); Log::addEditLog("Accepted change {$change->change_id} for {$xref} / {$change->gedcom_name} into database"); } }
break; case 'undoall': WT_DB::prepare("UPDATE `##change`" . " SET status='rejected'" . " WHERE status='pending' AND gedcom_id=?")->execute(array(WT_GED_ID)); break; case 'acceptall': $changes = WT_DB::prepare("SELECT change_id, gedcom_id, gedcom_name, xref, old_gedcom, new_gedcom" . " FROM `##change` c" . " JOIN `##gedcom` g USING (gedcom_id)" . " WHERE c.status='pending' AND gedcom_id=?" . " ORDER BY change_id")->execute(array(WT_GED_ID))->fetchAll(); foreach ($changes as $change) { if (empty($change->new_gedcom)) { // delete update_record($change->old_gedcom, $change->gedcom_id, true); } else { // add/update update_record($change->new_gedcom, $change->gedcom_id, false); } WT_DB::prepare("UPDATE `##change` SET status='accepted' WHERE change_id=?")->execute(array($change->change_id)); Log::addEditLog("Accepted change {$change->change_id} for {$change->xref} / {$change->gedcom_name} into database"); } break; } $changed_gedcoms = WT_DB::prepare("SELECT g.gedcom_name" . " FROM `##change` c" . " JOIN `##gedcom` g USING (gedcom_id)" . " WHERE c.status='pending'" . " GROUP BY g.gedcom_name")->fetchOneColumn(); if ($changed_gedcoms) { $changes = WT_DB::prepare("SELECT c.*, u.user_name, u.real_name, g.gedcom_name, new_gedcom, old_gedcom" . " FROM `##change` c" . " JOIN `##user` u USING (user_id)" . " JOIN `##gedcom` g USING (gedcom_id)" . " WHERE c.status='pending'" . " ORDER BY gedcom_id, c.xref, c.change_id")->fetchAll(); $output = '<br><br><table class="list_table">'; $prev_xref = null; $prev_gedcom_id = null; foreach ($changes as $change) { preg_match('/^0 @' . WT_REGEX_XREF . '@ (' . WT_REGEX_TAG . ')/', $change->old_gedcom . $change->new_gedcom, $match); switch ($match[1]) { case 'INDI': $record = new WT_Individual($change->xref, $change->old_gedcom, $change->new_gedcom, $change->gedcom_id); break;
/** * Preforms a search and replace */ function SearchAndReplace() { global $STANDARD_NAME_FACTS, $ADVANCED_NAME_FACTS; $this->sgeds = array(WT_GED_ID => WT_GEDCOM); $this->srindi = 'yes'; $this->srfams = 'yes'; $this->srsour = 'yes'; $this->srnote = 'yes'; $oldquery = $this->query; $this->GeneralSearch(); //-- don't try to make any changes if nothing was found if (!$this->myindilist && !$this->myfamlist && !$this->mysourcelist && !$this->mynotelist) { return; } Log::addEditLog("Search And Replace old:" . $oldquery . " new:" . $this->replace); // Include edit functions. require_once WT_ROOT . 'includes/functions/functions_edit.php'; $adv_name_tags = preg_split("/[\\s,;: ]+/", $ADVANCED_NAME_FACTS); $name_tags = array_unique(array_merge($STANDARD_NAME_FACTS, $adv_name_tags)); $name_tags[] = '_MARNM'; foreach ($this->myindilist as $id => $record) { $oldRecord = $record->getGedcom(); $newRecord = $oldRecord; if ($this->replaceAll) { $newRecord = preg_replace("~" . $oldquery . "~i", $this->replace, $newRecord); } else { if ($this->replaceNames) { foreach ($name_tags as $tag) { $newRecord = preg_replace("~(\\d) " . $tag . " (.*)" . $oldquery . "(.*)~i", "\$1 " . $tag . " \$2" . $this->replace . "\$3", $newRecord); } } if ($this->replacePlaces) { if ($this->replacePlacesWord) { $newRecord = preg_replace('~(\\d) PLAC (.*)([,\\W\\s])' . $oldquery . '([,\\W\\s])~i', "\$1 PLAC \$2\$3" . $this->replace . "\$4", $newRecord); } else { $newRecord = preg_replace("~(\\d) PLAC (.*)" . $oldquery . "(.*)~i", "\$1 PLAC \$2" . $this->replace . "\$3", $newRecord); } } } //-- if the record changed replace the record otherwise remove it from the search results if ($newRecord != $oldRecord) { $record->updateRecord($newRecord, true); } else { unset($this->myindilist[$id]); } } foreach ($this->myfamlist as $id => $record) { $oldRecord = $record->getGedcom(); $newRecord = $oldRecord; if ($this->replaceAll) { $newRecord = preg_replace("~" . $oldquery . "~i", $this->replace, $newRecord); } else { if ($this->replacePlaces) { if ($this->replacePlacesWord) { $newRecord = preg_replace('~(\\d) PLAC (.*)([,\\W\\s])' . $oldquery . '([,\\W\\s])~i', "\$1 PLAC \$2\$3" . $this->replace . "\$4", $newRecord); } else { $newRecord = preg_replace("~(\\d) PLAC (.*)" . $oldquery . "(.*)~i", "\$1 PLAC \$2" . $this->replace . "\$3", $newRecord); } } } //-- if the record changed replace the record otherwise remove it from the search results if ($newRecord != $oldRecord) { $record->updateRecord($newRecord, true); } else { unset($this->myfamlist[$id]); } } foreach ($this->mysourcelist as $id => $record) { $oldRecord = $record->getGedcom(); $newRecord = $oldRecord; if ($this->replaceAll) { $newRecord = preg_replace("~" . $oldquery . "~i", $this->replace, $newRecord); } else { if ($this->replaceNames) { $newRecord = preg_replace("~(\\d) TITL (.*)" . $oldquery . "(.*)~i", "\$1 TITL \$2" . $this->replace . "\$3", $newRecord); $newRecord = preg_replace("~(\\d) ABBR (.*)" . $oldquery . "(.*)~i", "\$1 ABBR \$2" . $this->replace . "\$3", $newRecord); } if ($this->replacePlaces) { if ($this->replacePlacesWord) { $newRecord = preg_replace('~(\\d) PLAC (.*)([,\\W\\s])' . $oldquery . '([,\\W\\s])~i', "\$1 PLAC \$2\$3" . $this->replace . "\$4", $newRecord); } else { $newRecord = preg_replace("~(\\d) PLAC (.*)" . $oldquery . "(.*)~i", "\$1 PLAC \$2" . $this->replace . "\$3", $newRecord); } } } //-- if the record changed replace the record otherwise remove it from the search results if ($newRecord != $oldRecord) { $record->updateRecord($newRecord, true); } else { unset($this->mysourcelist[$id]); } } foreach ($this->mynotelist as $id => $record) { $oldRecord = $record->getGedcom(); $newRecord = $oldRecord; if ($this->replaceAll) { $newRecord = preg_replace("~" . $oldquery . "~i", $this->replace, $newRecord); } //-- if the record changed replace the record otherwise remove it from the search results if ($newRecord != $oldRecord) { $record->updateRecord($newRecord, true); } else { unset($this->mynotelist[$id]); } } }
} } } // Insert the 1 FILE xxx record into the arrays used by function handle_updates() $glevels = array_merge(array('1'), $glevels); $tag = array_merge(array('FILE'), $tag); $islink = array_merge(array(0), $islink); $text = array_merge(array($newFilename), $text); $record = WT_GedcomRecord::getInstance($pid); $newrec = "0 @{$pid}@ OBJE\n"; $newrec = handle_updates($newrec); $record->updateRecord($newrec, $update_CHAN); if ($pid && $linktoid) { $record = WT_GedcomRecord::getInstance($linktoid); $record->createFact('1 OBJE @' . $pid . '@', true); Log::addEditLog('Media ID ' . $pid . " successfully added to {$linktoid}."); } $controller->pageHeader(); if ($messages) { echo '<button onclick="closePopupAndReloadParent();">', WT_I18N::translate('close'), '</button>'; } else { $controller->addInlineJavascript('closePopupAndReloadParent();'); } exit; case 'showmediaform': $controller->setPageTitle(WT_I18N::translate('Create a new media object')); $action = 'create'; break; case 'editmedia': $controller->setPageTitle(WT_I18N::translate('Edit media object')); $action = 'update';