本文整理汇总了PHP中DoliDB::getVersionArray方法的典型用法代码示例。如果您正苦于以下问题:PHP DoliDB::getVersionArray方法的具体用法?PHP DoliDB::getVersionArray怎么用?PHP DoliDB::getVersionArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DoliDB
的用法示例。
在下文中一共展示了DoliDB::getVersionArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: migrate_restore_missing_links
/**
* Migration du champ fk_remise_except dans llx_facturedet doit correspondre a
* lien dans llx_societe_remise_except vers llx_facturedet
*
* @param DoliDB $db Database handler
* @param Translate $langs Object langs
* @param Conf $conf Object conf
* @return void
*/
function migrate_restore_missing_links($db, $langs, $conf)
{
dolibarr_install_syslog("upgrade2::migrate_restore_missing_links");
if ($db->type == 'mysql' || $db->type == 'mysqli') {
if (versioncompare($db->getVersionArray(), array(4, 0)) < 0) {
dolibarr_install_syslog("upgrade2::migrate_restore_missing_links Version of database too old to make this migrate action");
return 0;
}
}
print '<tr><td colspan="4">';
print '<br>';
print '<b>' . $langs->trans('MigrationFixData') . "</b> (1)<br>\n";
$error = 0;
// Restore missing link for this cross foreign key (link 1 <=> 1). Direction 1.
$table1 = 'facturedet';
$field1 = 'fk_remise_except';
$table2 = 'societe_remise_except';
$field2 = 'fk_facture_line';
$db->begin();
$sql = "SELECT t1.rowid, t1." . $field1 . " as field";
$sql .= " FROM " . MAIN_DB_PREFIX . $table1 . " as t1";
$sql .= " WHERE t1." . $field1 . " IS NOT NULL AND t1." . $field1 . " NOT IN";
$sql .= " (SELECT t2.rowid FROM " . MAIN_DB_PREFIX . $table2 . " as t2";
$sql .= " WHERE t1.rowid = t2." . $field2 . ")";
dolibarr_install_syslog("upgrade2:migrate_restore_missing_links DIRECTION 1", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
if ($num) {
while ($i < $num) {
$obj = $db->fetch_object($resql);
print 'Line ' . $obj->rowid . ' in ' . $table1 . ' is linked to record ' . $obj->field . ' in ' . $table2 . ' that has no link to ' . $table1 . '. We fix this.<br>';
$sql = "UPDATE " . MAIN_DB_PREFIX . $table2 . " SET";
$sql .= " " . $field2 . " = '" . $obj->rowid . "'";
$sql .= " WHERE rowid=" . $obj->field;
$resql2 = $db->query($sql);
if (!$resql2) {
$error++;
dol_print_error($db);
}
//print ". ";
$i++;
}
} else {
print $langs->trans('AlreadyDone') . "<br>\n";
}
if ($error == 0) {
$db->commit();
} else {
$db->rollback();
}
} else {
dol_print_error($db);
$db->rollback();
}
print '</td></tr>';
print '<tr><td colspan="4">';
print '<br>';
print '<b>' . $langs->trans('MigrationFixData') . "</b> (2)<br>\n";
// Restore missing link for this cross foreign key (link 1 <=> 1). Direction 2.
$table2 = 'facturedet';
$field2 = 'fk_remise_except';
$table1 = 'societe_remise_except';
$field1 = 'fk_facture_line';
$db->begin();
$sql = "SELECT t1.rowid, t1." . $field1 . " as field";
$sql .= " FROM " . MAIN_DB_PREFIX . $table1 . " as t1";
$sql .= " WHERE t1." . $field1 . " IS NOT NULL AND t1." . $field1 . " NOT IN";
$sql .= " (SELECT t2.rowid FROM " . MAIN_DB_PREFIX . $table2 . " as t2";
$sql .= " WHERE t1.rowid = t2." . $field2 . ")";
dolibarr_install_syslog("upgrade2:migrate_restore_missing_links DIRECTION 2", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
if ($num) {
while ($i < $num) {
$obj = $db->fetch_object($resql);
print 'Line ' . $obj->rowid . ' in ' . $table1 . ' is linked to record ' . $obj->field . ' in ' . $table2 . ' that has no link to ' . $table1 . '. We fix this.<br>';
$sql = "UPDATE " . MAIN_DB_PREFIX . $table2 . " SET";
$sql .= " " . $field2 . " = '" . $obj->rowid . "'";
$sql .= " WHERE rowid=" . $obj->field;
$resql2 = $db->query($sql);
if (!$resql2) {
$error++;
dol_print_error($db);
}
//print ". ";
$i++;
}
//.........这里部分代码省略.........