/**
* Check with the webtrees.net server for the latest version of webtrees.
* Fetching the remote file can be slow, so check infrequently, and cache the result.
* Pass the current versions of webtrees, PHP and MySQL, as the response
* may be different for each. The server logs are used to generate
* installation statistics which can be found at http://svn.webtrees.net/statistics.html
*
* @return null|string
*/
public static function fetchLatestVersion()
{
$last_update_timestamp = Site::getPreference('LATEST_WT_VERSION_TIMESTAMP');
if ($last_update_timestamp < WT_TIMESTAMP - 24 * 60 * 60) {
$row = Database::prepare("SHOW VARIABLES LIKE 'version'")->fetchOneRow();
$params = '?w=' . WT_VERSION . '&p=' . PHP_VERSION . '&m=' . $row->value . '&o=' . (DIRECTORY_SEPARATOR === '/' ? 'u' : 'w');
$latest_version_txt = File::fetchUrl('http://dev.webtrees.net/build/latest-version.txt' . $params);
if ($latest_version_txt) {
Site::setPreference('LATEST_WT_VERSION', $latest_version_txt);
Site::setPreference('LATEST_WT_VERSION_TIMESTAMP', WT_TIMESTAMP);
return $latest_version_txt;
} else {
// Cannot connect to server - use cached version (if we have one)
return Site::getPreference('LATEST_WT_VERSION');
}
} else {
return Site::getPreference('LATEST_WT_VERSION');
}
}
echo I18N::translate('members');
?>
</span>
</div>
</div>
<div class="col-sm-8">
<?php
echo FunctionsEdit::selectEditControl('REQUIRE_AUTHENTICATION', array('0' => I18N::translate('Show to visitors'), '1' => I18N::translate('Show to members')), null, $WT_TREE->getPreference('REQUIRE_AUTHENTICATION'), 'class="form-control"');
?>
<p class="small text-muted">
<?php
echo I18N::translate('Enabling this option will force all visitors to sign in before they can view any data on the website.');
?>
</p>
<?php
if (Site::getPreference('USE_REGISTRATION_MODULE')) {
?>
<p class="small text-muted">
<?php
echo I18N::translate('If visitors can not see the family tree, they will not be able to sign up for an account. You will need to add their account manually.');
?>
</p>
<?php
}
?>
</div>
</div>
<!-- SHOW_DEAD_PEOPLE -->
<div class="form-group">
<div class="control-label col-sm-4">
/**
* Create a transport mechanism for sending mail
*
* @return Swift_Transport
*/
public static function transport()
{
switch (Site::getPreference('SMTP_ACTIVE')) {
case 'internal':
return Swift_MailTransport::newInstance();
case 'external':
$transport = Swift_SmtpTransport::newInstance()->setHost(Site::getPreference('SMTP_HOST'))->setPort(Site::getPreference('SMTP_PORT'))->setLocalDomain(Site::getPreference('SMTP_HELO'));
if (Site::getPreference('SMTP_AUTH')) {
$transport->setUsername(Site::getPreference('SMTP_AUTH_USER'))->setPassword(Site::getPreference('SMTP_AUTH_PASS'));
}
if (Site::getPreference('SMTP_SSL') !== 'none') {
$transport->setEncryption(Site::getPreference('SMTP_SSL'));
}
return $transport;
default:
// For testing
return Swift_NullTransport::newInstance();
}
}
/**
* Run a series of scripts to bring the database schema up to date.
*
* @param string $namespace Where to find our MigrationXXX classes
* @param string $schema_name Where to find our MigrationXXX classes
* @param int $target_version updade/downgrade to this version
*
* @throws PDOException
*
* @return bool Were any updates applied
*/
public static function updateSchema($namespace, $schema_name, $target_version)
{
try {
$current_version = (int) Site::getPreference($schema_name);
} catch (PDOException $e) {
// During initial installation, the site_preference table won’t exist.
$current_version = 0;
}
$updates_applied = false;
try {
// Update the schema, one version at a time.
while ($current_version < $target_version) {
$class = $namespace . '\\Migration' . $current_version;
/** @var MigrationInterface $migration */
$migration = new $class();
$migration->upgrade();
Site::setPreference($schema_name, ++$current_version);
$updates_applied = true;
}
} catch (PDOException $ex) {
// The schema update scripts should never fail. If they do, there is no clean recovery.
FlashMessages::addMessage($ex->getMessage(), 'danger');
header('Location: ' . WT_BASE_URL . 'site-unavailable.php');
throw $ex;
}
return $updates_applied;
}
Database::exec("DELETE FROM `##user` WHERE user_id>0");
////////////////////////////////////////////////////////////////////////////////
echo '<p>', $INDEX_DIRECTORY, 'config.php => wt_site_setting…</p>';
Site::setPreference('USE_REGISTRATION_MODULE', $USE_REGISTRATION_MODULE);
Site::setPreference('ALLOW_USER_THEMES', $ALLOW_USER_THEMES);
Site::setPreference('ALLOW_CHANGE_GEDCOM', $ALLOW_CHANGE_GEDCOM);
Site::setPreference('SESSION_TIME', $PGV_SESSION_TIME);
Site::setPreference('SMTP_ACTIVE', $PGV_SMTP_ACTIVE ? 'external' : 'internal');
Site::setPreference('SMTP_HOST', $PGV_SMTP_HOST);
Site::setPreference('SMTP_HELO', $PGV_SMTP_HELO);
Site::setPreference('SMTP_PORT', $PGV_SMTP_PORT);
Site::setPreference('SMTP_AUTH', $PGV_SMTP_AUTH);
Site::setPreference('SMTP_AUTH_USER', $PGV_SMTP_AUTH_USER);
Site::setPreference('SMTP_AUTH_PASS', $PGV_SMTP_AUTH_PASS);
Site::setPreference('SMTP_SSL', $PGV_SMTP_SSL);
Site::setPreference('SMTP_FROM_NAME', $PGV_SMTP_FROM_NAME);
////////////////////////////////////////////////////////////////////////////////
echo '<p>pgv_site_setting => wt_site_setting…</p>';
Database::prepare("REPLACE INTO `##site_setting` (setting_name, setting_value)" . " SELECT site_setting_name, site_setting_value FROM `{$DBNAME}`.`{$TBLPREFIX}site_setting`" . " WHERE site_setting_name IN ('DEFAULT_GEDCOM', 'LAST_CHANGE_EMAIL')")->execute();
////////////////////////////////////////////////////////////////////////////////
if ($PGV_SCHEMA_VERSION >= 12) {
echo '<p>pgv_gedcom => wt_gedcom…</p>';
Database::prepare("INSERT INTO `##gedcom` (gedcom_id, gedcom_name)" . " SELECT gedcom_id, gedcom_name FROM `{$DBNAME}`.`{$TBLPREFIX}gedcom`")->execute();
echo '<p>pgv_gedcom_setting => wt_gedcom_setting…</p>';
Database::prepare("INSERT INTO `##gedcom_setting` (gedcom_id, setting_name, setting_value)" . " SELECT gedcom_id, setting_name," . " CASE setting_name" . " WHEN 'THEME_DIR' THEN" . " CASE setting_value" . " WHEN '' THEN ''" . " WHEN 'themes/cloudy/' THEN 'clouds'" . " WHEN 'themes/minimal/' THEN 'minimal'" . " WHEN 'themes/simplyblue/' THEN 'colors'" . " WHEN 'themes/simplygreen/' THEN 'colors'" . " WHEN 'themes/simplyred/' THEN 'colors'" . " WHEN 'themes/xenea/' THEN 'xenea'" . " ELSE 'themes/webtrees/'" . " END" . " WHEN 'LANGUAGE' THEN" . " CASE setting_value" . " WHEN 'arabic' THEN 'ar'" . " WHEN 'catalan' THEN 'ca'" . " WHEN 'chinese' THEN 'zh_CN'" . " WHEN 'croatian' THEN 'hr'" . " WHEN 'danish' THEN 'da'" . " WHEN 'dutch' THEN 'nl'" . " WHEN 'english' THEN 'en_US'" . " WHEN 'english-uk' THEN 'en_GB'" . " WHEN 'estonian' THEN 'et'" . " WHEN 'finnish' THEN 'fi'" . " WHEN 'french' THEN 'fr'" . " WHEN 'german' THEN 'de'" . " WHEN 'greek' THEN 'el'" . " WHEN 'hebrew' THEN 'he'" . " WHEN 'hungarian' THEN 'hu'" . " WHEN 'indonesian' THEN 'id'" . " WHEN 'italian' THEN 'it'" . " WHEN 'lithuanian' THEN 'lt'" . " WHEN 'norwegian' THEN 'nn'" . " WHEN 'polish' THEN 'pl'" . " WHEN 'portuguese' THEN 'pt'" . " WHEN 'romainian' THEN 'ro'" . " WHEN 'russian' THEN 'ru'" . " WHEN 'serbian-la' THEN 'sr@Latn'" . " WHEN 'slovak' THEN 'sk'" . " WHEN 'slovenian' THEN 'sl'" . " WHEN 'spanish' THEN 'es'" . " WHEN 'spanish-ar' THEN 'es'" . " WHEN 'swedish' THEN 'sv'" . " WHEN 'turkish' THEN 'tr'" . " WHEN 'vietnamese' THEN 'vi'" . " ELSE 'en_US'" . " END" . " ELSE setting_value" . " END" . " FROM `{$DBNAME}`.`{$TBLPREFIX}gedcom_setting`" . " WHERE setting_name NOT IN ('HOME_SITE_TEXT', 'HOME_SITE_URL')")->execute();
echo '<p>pgv_user => wt_user…</p>';
try {
// "INSERT IGNORE" is needed to allow for PhpGedView users with duplicate emails. Only the first will be imported.
Database::prepare("INSERT IGNORE INTO `##user` (user_id, user_name, real_name, email, password)" . " SELECT user_id, user_name, CONCAT_WS(' ', us1.setting_value, us2.setting_value), us3.setting_value, password FROM `{$DBNAME}`.`{$TBLPREFIX}user`" . " LEFT JOIN `{$DBNAME}`.`{$TBLPREFIX}user_setting` us1 USING (user_id)" . " LEFT JOIN `{$DBNAME}`.`{$TBLPREFIX}user_setting` us2 USING (user_id)" . " JOIN `{$DBNAME}`.`{$TBLPREFIX}user_setting` us3 USING (user_id)" . " WHERE us1.setting_name='firstname'" . " AND us2.setting_name='lastname'" . " AND us3.setting_name='email'")->execute();
} catch (PDOException $ex) {
// Ignore duplicates
请发表评论