Esempio n. 1
0
function db_project_create($dbname)
{
    /*
         Create the db if it does not exist and grant read access only
         to the user 'cxuser'
         CAUTION!! The codendiadm user must have GRANT privilege granted 
         for this to work. This can be done from the mysql shell with:
            $ mysql -u root mysql -p
            mysql> UPDATE user SET Grant_priv='Y' where User='******';
            mysql> FLUSH PRIVILEGES;
    */
    // make sure the database name is not the same as the
    // system database name !!!!
    if ($dbname != $GLOBALS['sys_dbname']) {
        db_query('CREATE DATABASE IF NOT EXISTS `' . $dbname . '`');
        db_project_query($dbname, 'GRANT SELECT ON `' . $dbname . '`.* TO cxuser@\'%\'');
        return true;
    } else {
        return false;
    }
}
             // Check if this tracker is valid (not deleted) && the database has been exported
             if (!$at->isValid() && db_database_exist($dbname)) {
                 db_project_query($dbname, 'DROP TABLE IF EXISTS ' . $tbl_name);
                 continue;
             }
             // Create field factory
             $art_field_fact = new ArtifactFieldFactory($at);
             if ($art_field_fact->isError()) {
                 exit_error($Language->getText('global', 'error'), $art_field_fact->getErrorMessage());
             }
             // Let's create the project database if it does not exist
             // Drop the existing table and create a fresh one
             db_project_create($dbname);
             db_project_query($dbname, 'DROP TABLE IF EXISTS ' . $tbl_name);
             $sql_create = "CREATE TABLE {$tbl_name} (" . 'artifact_id INTEGER, field_name VARCHAR(255), ' . 'old_value TEXT, new_value TEXT, mod_by VARCHAR(255), email TEXT, date DATETIME, ' . 'type VARCHAR(255), ' . 'label VARCHAR(255) ' . ')';
             $res = db_project_query($dbname, $sql_create);
             // extract data from the bug table and insert them into
             // the project database table
             if ($res) {
                 $result = extract_history($atid);
                 while ($arr = db_fetch_array($result)) {
                     prepare_artifact_history_record($at, $art_field_fact, $arr);
                     insert_record_in_table($dbname, $tbl_name, $col_list, $arr);
                 }
             } else {
                 $feedback .= $Language->getText('project_export_artifact_deps_export', 'create_proj_err', array($tbl_name, db_project_error()));
             }
         }
         // for
     }
 } else {
Esempio n. 3
0
                             prepare_artifact_record($at, $fields, $atid, $arr, 'database');
                             insert_record_in_table($dbname, $tbl_name, $col_list, $arr);
                         }
                     }
                 } else {
                     $feedback .= $Language->getText('project_export_artifact_deps_export', 'create_proj_err', array($tbl_name, db_project_error()));
                 }
                 // MV add
                 // Export table structure
                 // Create table
                 $tbl_struct_name = "artifact_struct_" . $at_arr[$j]->getItemName();
                 $tbl_struct_name = str_replace(' ', '_', $tbl_struct_name);
                 $fieldsList = $art_field_fact->getAllUsedFields();
                 db_project_query($dbname, 'DROP TABLE IF EXISTS ' . $tbl_struct_name);
                 $struct_table_create = 'CREATE TABLE ' . $tbl_struct_name . '(' . ' field_name VARCHAR(255), ' . ' field_label VARCHAR(255)' . ')';
                 db_project_query($dbname, $struct_table_create);
                 // Populate table
                 $struct_col_list = array('field_name', 'field_label');
                 foreach ($fieldsList as $art_field) {
                     $struct_arr['field_name'] = $art_field->getName();
                     $struct_arr['field_label'] = $art_field->getLabel();
                     insert_record_in_table($dbname, $tbl_struct_name, $struct_col_list, $struct_arr);
                 }
             }
             // for
         }
         // if
     } else {
         $feedback .= $Language->getText('project_export_artifact_deps_export', 'security_violation', $dbname);
     }
 }