当前位置: 首页>>代码示例>>PHP>>正文


PHP DoliDB::getVersionArray方法代码示例

本文整理汇总了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++;
            }
//.........这里部分代码省略.........
开发者ID:ADDAdev,项目名称:Dolibarr,代码行数:101,代码来源:upgrade2.php


注:本文中的DoliDB::getVersionArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。