Example #1
0
 /**
  * Paper表数据插入
  * @throws Exception
  * @return boolean
  * [1] 插入成功
  * [0|Exception] 插入失败
  */
 public static function insertPaperData()
 {
     if (Paper::count() != 0) {
         throw new Exception("The Paper table is already inserted, please delete it and then insert or update!");
     }
     $paper_data = Paper::getLastedDataFromModel();
     $data_type = self::dataFormatCheck($paper_data);
     if ($data_type != 5) {
         throw new Exception("input type is not available!");
     }
     try {
         $manager = new TxManager();
         $transaction = $manager->get();
         foreach ($paper_data as $record) {
             $paper = new Paper();
             $paper->description = $record['description'];
             $paper->name = $record['name'];
             if ($paper->create() == false) {
                 $transaction->rollback("Cannot insert Paper data");
             }
         }
         $transaction->commit();
         return true;
     } catch (TxFailed $e) {
         throw new Exception("Failed, reason: " . $e->getMessage());
     }
 }