Exemplo n.º 1
0
/**
 * Migrate link stored into fk_xxxx into fk_element and elementtype
 *
 * @param	DoliDB		$db		Database handler
 * @param	Translate	$langs	Object langs
 * @param	Conf		$conf	Object conf
 * @return	void
 */
function migrate_actioncomm_element($db, $langs, $conf)
{
    print '<tr><td colspan="4">';
    print '<br>';
    print '<b>' . $langs->trans('MigrationActioncommElement') . "</b><br>\n";
    $elements = array('propal' => 'propalrowid', 'order' => 'fk_commande', 'invoice' => 'fk_facture', 'contract' => 'fk_contract', 'order_supplier' => 'fk_supplier_order', 'invoice_supplier' => 'fk_supplier_invoice');
    foreach ($elements as $type => $field) {
        $result = $db->DDLDescTable(MAIN_DB_PREFIX . "actioncomm", $field);
        $obj = $db->fetch_object($result);
        if ($obj) {
            dolibarr_install_syslog("upgrade2::migrate_actioncomm_element field=" . $field);
            $db->begin();
            $sql = "UPDATE " . MAIN_DB_PREFIX . "actioncomm SET ";
            $sql .= "fk_element = " . $field . ", elementtype = '" . $type . "'";
            $sql .= " WHERE " . $field . " IS NOT NULL";
            $sql .= " AND fk_element IS NULL";
            $sql .= " AND elementtype IS NULL";
            $resql = $db->query($sql);
            if ($resql) {
                $db->commit();
                // DDL commands must not be inside a transaction
                // We will drop at next version because a migrate should be runnable several times if it fails.
                //$sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."actioncomm DROP COLUMN ".$field;
                //$db->query($sqlDrop);
                //print ". ";
            } else {
                dol_print_error($db);
                $db->rollback();
            }
        } else {
            print $langs->trans('AlreadyDone') . "<br>\n";
        }
    }
    print '</td></tr>';
}