コード例 #1
0
ファイル: File.php プロジェクト: netconstructor/Centurion
 public function insert(array $data)
 {
     $primary = $this->_primary;
     if (is_array($primary)) {
         $primary = $primary[1];
     }
     if (!isset($data[$primary])) {
         $data[$primary] = md5(Centurion_Inflector::uniq(uniqid()));
     }
     if (!isset($data['sha1'])) {
         $data['sha1'] = sha1_file(Centurion_Config_Manager::get('media.uploads_dir') . DIRECTORY_SEPARATOR . $data['local_filename']);
     }
     $row = $this->fetchRow(array('sha1=?' => $data['sha1'], 'filesize=?' => $data['filesize']));
     //We want to be sure
     if ($row !== null && sha1_file(Centurion_Config_Manager::get('media.uploads_dir') . DIRECTORY_SEPARATOR . $data['local_filename']) == $row->sha1 && filesize(Centurion_Config_Manager::get('media.uploads_dir') . DIRECTORY_SEPARATOR . $data['local_filename']) == $row->filesize) {
         //We reuse the same local filename
         unlink(Centurion_Config_Manager::get('media.uploads_dir') . DIRECTORY_SEPARATOR . $data['local_filename']);
         $data['file_id'] = $row->file_id;
         $data['local_filename'] = $row->local_filename;
         $data['filesize'] = $row->filesize;
         $data['proxy_model'] = $row->proxy_model;
         $data['proxy_pk'] = $row->proxy_pk;
         $data['belong_model'] = $row->belong_model;
         $data['belong_pk'] = $row->belong_pk;
     }
     if (!isset($data['file_id'])) {
         $data['file_id'] = $data[$primary];
     }
     if (!isset($data['proxy_pk'])) {
         foreach ($this->_dependentProxies as $key => $dependentProxy) {
             $proxyTable = Centurion_Db::getSingletonByClassName($dependentProxy);
             if (!in_array($data['mime'], array_keys($proxyTable->getMimeTypes()))) {
                 continue;
             }
             $cols = $proxyTable->info('cols');
             $proxyData = array();
             foreach ($data as $key => $value) {
                 if ($key == $primary || !in_array($key, $cols)) {
                     continue;
                 }
                 $proxyData[$key] = $value;
                 unset($data[$key]);
             }
             $proxyData = $data;
             unset($proxyData[$primary]);
             $pk = $proxyTable->insert($proxyData);
             $data = array_merge($data, array('proxy_model' => $dependentProxy, 'proxy_pk' => $pk));
         }
     }
     if (array_key_exists(self::BELONG_TO, $data)) {
         list($model, $pk) = $this->_setupProxyBelong($data[self::BELONG_TO]);
         $data = array_merge($data, array('belong_model' => $model, 'belong_pk' => $pk));
         unset($data[self::BELONG_TO]);
     }
     return parent::insert($data);
 }
コード例 #2
0
ファイル: File.php プロジェクト: rom1git/Centurion
 /**
  * Receive the uploaded file
  *
  * @return boolean
  */
 public function receive()
 {
     $fileinfo = $this->getFileInfo();
     if (null === $this->_initialFilename) {
         $this->_initialFilename = $fileinfo[$this->getName()]['name'];
     }
     $dirName = md5(Centurion_Inflector::uniq($fileinfo[$this->getName()]['tmp_name']));
     $filename = substr($dirName, 0, 2) . DIRECTORY_SEPARATOR . substr($dirName, 2) . Centurion_Inflector::extension($fileinfo[$this->getName()]['name']);
     $this->_localFilename = $filename;
     if (!file_exists($this->getDestination() . DIRECTORY_SEPARATOR . substr($dirName, 0, 2))) {
         mkdir($this->getDestination() . DIRECTORY_SEPARATOR . substr($dirName, 0, 2), 0770, true);
     }
     $this->getTransferAdapter()->addFilter('Rename', array('target' => $this->getDestination() . DIRECTORY_SEPARATOR . $filename, 'overwrite' => true))->setOptions(array('useByteString' => false));
     // retrieve the real filesize
     return parent::receive();
 }
コード例 #3
0
ファイル: File.php プロジェクト: rom1git/Centurion
 public function _insert()
 {
     if (null == $this->id) {
         $this->id = md5(Centurion_Inflector::uniq(uniqid()));
     }
     $this->_populateData();
 }