Exemplo n.º 1
0
 /**
  * Funzione per creare le tabelle necessarie a ProPayment
  */
 private function checkTables()
 {
     // tabelle personalizzate modulo di pagamento
     if (method_exists($this->MODULE, "customTables")) {
         $customTables = $this->MODULE->customTables();
     } else {
         $customTables = array();
     }
     $table = new PPTable("#__propay_transactions");
     $table->addField("transaction_id", "INT", FALSE, NULL, TRUE);
     $table->addField("order_number", "CHAR(64)", FALSE);
     $table->addField("idtransazione", "VARCHAR(100)", FALSE);
     $table->addField("order_total", "decimal(15,5)", TRUE, 0);
     $table->addField("returned", "TINYINT", FALSE, "0");
     $table->addField("cdate", "INT", FALSE);
     $table->addField("user_id", "INT", FALSE);
     $table->addField("modulename", "VARCHAR(50)", FALSE);
     $table->addField("result", "CHAR(2)", TRUE);
     $table->addField("esito", "VARCHAR(50)", TRUE);
     $table->addField("language", "CHAR(5)", TRUE);
     $table->addField("status", "CHAR(1)", TRUE);
     $table->setPrimaryKey("transaction_id");
     $table->addIndex("idtransazione_UNIQUE", "idtransazione ASC", TRUE);
     $table->setComment("Registro transazioni moduli di pagamento ProPayment");
     $customTables[] = $table;
     foreach ($customTables as $table => $definition) {
         if (is_object($definition)) {
             // nuova modalità con oggetto PPTable
             $result = $definition->checkTable($this->db);
             echo "<div><strong>" . $result . "</strong></div>";
         } else {
             if (!$this->db->tableExists($table)) {
                 $q = "CREATE TABLE {$table} ( {$definition} )";
                 if (!$this->db->queryExec($q)) {
                     echo "<div><strong>Errore nella creazione della tabella " . $table . ": " . $this->db->getErrorMsg() . "</strong></div>";
                 } else {
                     echo "<div><strong>Tabella creata:" . $table . "</strong></div>";
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Inserisce o aggiorna la tabella
  * @param ProPayment_Database $db 
  * @return string Messaggio di creazione / aggiornamento o errore
  */
 public function checkTable($db)
 {
     $this->db = $db;
     if ($this->db->tableExists($this->name)) {
         $updated = false;
         // la tabella esiste: devo verificare i campi e gli indici
         foreach ($this->fields as $name => $def) {
             if (!$this->db->fieldExists($this->name, $name)) {
                 $q = "ALTER TABLE `" . $this->name . "` ADD COLUMN `" . $name . "` " . $def;
                 $result = $this->db->queryExec($q);
                 if (!$result) {
                     return "Errore nell'aggiunta del campo " . $name . " alla tabella " . $this->name . ": " . $this->db->getErrorMsg();
                 }
                 $updated = true;
             }
         }
         foreach ($this->indexes as $name => $def) {
             if (!$this->db->indexExists($this->name, $name)) {
                 $q = "ALTER TABLE `" . $this->name . "` ADD " . $def;
                 $result = $this->db->queryExec($q);
                 if (!$result) {
                     return "Errore nell'aggiunta dell'indice " . $name . " alla tabella " . $this->name . ": " . $this->db->getErrorMsg();
                 }
                 $updated = true;
             }
         }
         if ($updated) {
             return "Tabella aggiornata: " . $this->name;
         } else {
             return "";
         }
     } else {
         // la tabella non esiste: la devo creare
         $q = $this->buildCreateTableQuery();
         $result = $this->db->queryExec($q);
         if ($result) {
             return "Tabella creata: " . $this->name;
         } else {
             return "Errore nella creazione della tabella " . $this->name . ": " . $this->db->getErrorMsg();
         }
     }
 }