Database::rollBack(); echo '<span class="error">', I18N::translate('Error: converting GEDCOM files from %s encoding to UTF-8 encoding not currently supported.', $charset), '</span>'; $controller->addInlineJavascript('jQuery("#actions' . $gedcom_id . '").removeClass("hidden");'); return; } $first_time = false; // Re-fetch the data, now that we have performed character set conversion. $data = Database::prepare("SELECT gedcom_chunk_id, REPLACE(chunk_data, '\r', '\n') AS chunk_data" . " FROM `##gedcom_chunk`" . " WHERE gedcom_chunk_id=?")->execute(array($data->gedcom_chunk_id))->fetchOneRow(); } if (!$data) { break; } try { // Import all the records in this chunk of data foreach (preg_split('/\\n+(?=0)/', $data->chunk_data) as $rec) { FunctionsImport::importRecord($rec, $tree, false); } // Mark the chunk as imported Database::prepare("UPDATE `##gedcom_chunk` SET imported=TRUE WHERE gedcom_chunk_id=?")->execute(array($data->gedcom_chunk_id)); } catch (PDOException $ex) { Database::rollBack(); if ($ex->getCode() === '40001') { // "SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction" // The documentation says that if you get this error, wait and try again..... $controller->addInlineJavascript('jQuery("#import' . $gedcom_id . '").load("import.php?gedcom_id=' . $gedcom_id . '&u=' . uniqid() . '");'); } else { // A fatal error. Nothing we can do? echo '<span class="error">', $ex->getMessage(), '</span>'; $controller->addInlineJavascript('jQuery("#actions' . $gedcom_id . '").removeClass("hidden");'); } return;
// Level 2-3 links $source->updateFact($fact->getFactId(), preg_replace(array('/\\n2 OBJE @' . $target . '@(\\n[3-9].*)*/', '/\\n3 OBJE @' . $target . '@(\\n[4-9].*)*/'), '', $fact->getGedcom()), true); } } } } } else { http_response_code(406); } break; case 'reject-changes': // Reject all the pending changes for a record $record = GedcomRecord::getInstance(Filter::post('xref', WT_REGEX_XREF), $WT_TREE); if ($record && $record->canEdit() && Auth::isModerator($record->getTree())) { FlashMessages::addMessage(I18N::translate('The changes to “%s” have been rejected.', $record->getFullName())); FunctionsImport::rejectAllChanges($record); } else { http_response_code(406); } break; case 'theme': // Change the current theme $theme = Filter::post('theme'); if (Site::getPreference('ALLOW_USER_THEMES') && array_key_exists($theme, Theme::themeNames())) { Session::put('theme_id', $theme); // Remember our selection Auth::user()->setPreference('theme', $theme); } else { // Request for a non-existant theme. http_response_code(406); }
} } } // Insert the 1 FILE xxx record into the arrays used by function FunctionsEdit::handle_updatesges() $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 = GedcomRecord::getInstance($pid, $WT_TREE); $newrec = "0 @{$pid}@ OBJE\n"; $newrec = FunctionsEdit::handleUpdates($newrec); $record->updateRecord($newrec, $update_CHAN); if ($move_file) { // We've moved a file. Therefore we must approve the change, as rejecting // the change will create broken references. FunctionsImport::acceptAllChanges($record->getXref(), $record->getTree()->getTreeId()); } if ($pid && $linktoid) { $record = GedcomRecord::getInstance($linktoid, $WT_TREE); $record->createFact('1 OBJE @' . $pid . '@', true); Log::addEditLog('Media ID ' . $pid . " successfully added to {$linktoid}."); } $controller->pageHeader(); if ($messages) { echo '<button onclick="closePopupAndReloadParent();">', I18N::translate('close'), '</button>'; } else { $controller->addInlineJavascript('closePopupAndReloadParent();'); } return; case 'showmediaform': $controller->setPageTitle(I18N::translate('Create a new media object'));
/** * Create a new record from GEDCOM data. * * @param string $gedcom * * @throws \Exception * * @return GedcomRecord */ public function createRecord($gedcom) { if (preg_match('/^0 @(' . WT_REGEX_XREF . ')@ (' . WT_REGEX_TAG . ')/', $gedcom, $match)) { $xref = $match[1]; $type = $match[2]; } else { throw new \Exception('Invalid argument to GedcomRecord::createRecord(' . $gedcom . ')'); } if (strpos("\r", $gedcom) !== false) { // MSDOS line endings will break things in horrible ways throw new \Exception('Evil line endings found in GedcomRecord::createRecord(' . $gedcom . ')'); } // webtrees creates XREFs containing digits. Anything else (e.g. “new”) is just a placeholder. if (!preg_match('/\\d/', $xref)) { $xref = $this->getNewXref($type); $gedcom = preg_replace('/^0 @(' . WT_REGEX_XREF . ')@/', '0 @' . $xref . '@', $gedcom); } // Create a change record, if not already present if (!preg_match('/\\n1 CHAN/', $gedcom)) { $gedcom .= "\n1 CHAN\n2 DATE " . date('d M Y') . "\n3 TIME " . date('H:i:s') . "\n2 _WT_USER " . Auth::user()->getUserName(); } // Create a pending change Database::prepare("INSERT INTO `##change` (gedcom_id, xref, old_gedcom, new_gedcom, user_id) VALUES (?, ?, '', ?, ?)")->execute(array($this->tree_id, $xref, $gedcom, Auth::id())); Log::addEditLog('Create: ' . $type . ' ' . $xref); // Accept this pending change if (Auth::user()->getPreference('auto_accept')) { FunctionsImport::acceptAllChanges($xref, $this->tree_id); } // Return the newly created record. Note that since GedcomRecord // has a cache of pending changes, we cannot use it to create a // record with a newly created pending change. return GedcomRecord::getInstance($xref, $this, $gedcom); }
Database::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; case 'undoall': Database::prepare("UPDATE `##change`" . " SET status='rejected'" . " WHERE status='pending' AND gedcom_id=?")->execute(array($WT_TREE->getTreeId())); break; case 'acceptall': $changes = Database::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_TREE->getTreeId()))->fetchAll(); foreach ($changes as $change) { if (empty($change->new_gedcom)) { // delete FunctionsImport::updateRecord($change->old_gedcom, $change->gedcom_id, true); } else { // add/update FunctionsImport::updateRecord($change->new_gedcom, $change->gedcom_id, false); } Database::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 = Database::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 = Database::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) { $tree = Tree::findById($change->gedcom_id); preg_match('/^0 @' . WT_REGEX_XREF . '@ (' . WT_REGEX_TAG . ')/', $change->old_gedcom . $change->new_gedcom, $match);
/** * Delete this record */ public function deleteRecord() { // Create a pending change if (!$this->isPendingDeletion()) { Database::prepare("INSERT INTO `##change` (gedcom_id, xref, old_gedcom, new_gedcom, user_id) VALUES (?, ?, ?, '', ?)")->execute(array($this->tree->getTreeId(), $this->xref, $this->getGedcom(), Auth::id())); } // Auto-accept this pending change if (Auth::user()->getPreference('auto_accept')) { FunctionsImport::acceptAllChanges($this->xref, $this->tree->getTreeId()); } // Clear the cache self::$gedcom_record_cache = null; self::$pending_record_cache = null; Log::addEditLog('Delete: ' . static::RECORD_TYPE . ' ' . $this->xref); }