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


PHP Kwf_Model_Abstract::import方法代码示例

本文整理汇总了PHP中Kwf_Model_Abstract::import方法的典型用法代码示例。如果您正苦于以下问题:PHP Kwf_Model_Abstract::import方法的具体用法?PHP Kwf_Model_Abstract::import怎么用?PHP Kwf_Model_Abstract::import使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Kwf_Model_Abstract的用法示例。


在下文中一共展示了Kwf_Model_Abstract::import方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: import

 public function import($format, $data, $options = array())
 {
     if ($format == self::FORMAT_ARRAY) {
         if (isset($options['replace']) && $options['replace']) {
             throw new Kwf_Exception_NotYetImplemented();
         }
         $ret = $this->getCollection()->batchInsert($data, array('safe' => true));
         if (!$ret || !$ret['ok']) {
             throw new Kwf_Exception("import failed");
         }
     } else {
         parent::import($format, $data, $options);
     }
 }
开发者ID:xiaoguizhidao,项目名称:koala-framework,代码行数:14,代码来源:Mongo.php

示例2: import

 public function import($format, $data, $options = array())
 {
     if ($format == self::FORMAT_SQL) {
         // if no data is recieved, quit
         if (!$data) {
             return;
         }
         $filename = tempnam('/tmp', 'modelimport');
         file_put_contents($filename, $data);
         $systemData = $this->_getSystemData();
         $cmd = "gunzip -c {$filename} ";
         if (isset($options['replace']) && $options['replace']) {
             $cmd .= "| sed -e \"s|INSERT INTO|REPLACE INTO|\"";
         }
         if (isset($options['ignorePrimaryKey']) && $options['ignorePrimaryKey']) {
             $primaryKey = $this->getPrimaryKey();
             $cmd .= " | sed -e \"s|(\\`" . $primaryKey . "\\`,|(|\" -e \"s|([0-9]*,|(|g\"";
         }
         $cmd .= "| {$systemData['mysqlDir']}mysql {$systemData['mysqlOptions']} 2>&1";
         exec($cmd, $output, $ret);
         unlink($filename);
         $this->_updateModelObserver($options, null);
         if ($ret != 0) {
             throw new Kwf_Exception("SQL import failed: " . implode("\n", $output));
         }
         $this->_afterImport($format, $data, $options);
     } else {
         if ($format == self::FORMAT_CSV) {
             // if no data is recieved, quit
             if (!$data) {
                 return;
             }
             $tmpImportFolder = tempnam('temp/', 'modelcsvim');
             unlink($tmpImportFolder);
             mkdir($tmpImportFolder, 0777);
             $filename = $tmpImportFolder . '/csvimport';
             file_put_contents($filename . '.gz', $data);
             $cmd = "gunzip -c {$filename}.gz > {$filename}" . " && head --lines=1 {$filename} | sed -e 's|\"|`|g'";
             exec($cmd, $output, $ret);
             if ($ret != 0) {
                 throw new Kwf_Exception("CSV-SQL export failed");
             }
             $fieldNames = trim($output[0]);
             if ($fieldNames) {
                 // set the character_set_database MySQL system variable to utf8
                 $this->executeSql("SET character_set_database = 'utf8'");
                 $sqlString = "LOAD DATA INFILE '{$filename}'";
                 if (isset($options['replace']) && $options['replace']) {
                     $sqlString .= " REPLACE";
                 }
                 $sqlString .= " INTO TABLE `" . $this->getTableName() . "`";
                 $sqlString .= " FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' ESCAPED BY '\\\\' LINES TERMINATED BY '\\n'";
                 $sqlString .= " IGNORE 1 LINES";
                 $sqlString .= " ({$fieldNames})";
                 $this->executeSql($sqlString);
             }
             unlink($filename . '.gz');
             unlink($filename);
             rmdir($tmpImportFolder);
             $this->_updateModelObserver($options, null);
             $this->_afterImport($format, $data, $options);
         } else {
             if ($format == self::FORMAT_ARRAY) {
                 $ids = array();
                 foreach ($data as $k => $v) {
                     if (is_array($ids) && !is_array($this->getPrimaryKey()) && isset($v[$this->getPrimaryKey()])) {
                         $ids[] = $v[$this->getPrimaryKey()];
                     } else {
                         //if we don't know all imported ids, pass null
                         $ids = null;
                     }
                 }
                 if (isset($options['buffer']) && $options['buffer']) {
                     if (isset($this->_importBuffer)) {
                         if ($options != $this->_importBufferOptions) {
                             throw new Kwf_Exception_NotYetImplemented("You can't buffer imports with different options (not yet implemented)");
                         }
                         $this->_importBuffer = array_merge($this->_importBuffer, $data);
                         // handling for not sending too much data to mysql in one query
                         // is in _importArray() function
                     } else {
                         $this->_importBufferOptions = $options;
                         $this->_importBuffer = $data;
                     }
                     if ($this->_getBufferLogFileName()) {
                         file_put_contents($this->_getBufferLogFileName(), count($this->_importBuffer));
                     }
                     if ($options['buffer'] !== true && count($this->_importBuffer) > $options['buffer']) {
                         $this->writeBuffer();
                     }
                 } else {
                     $this->_importArray($data, $options);
                 }
                 $this->_updateModelObserver($options, $ids);
                 $this->_afterImport($format, $data, $options);
             } else {
                 parent::import($format, $data);
             }
         }
     }
//.........这里部分代码省略.........
开发者ID:nsams,项目名称:koala-framework,代码行数:101,代码来源:Db.php


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