function run($runtime)
 {
     $errors = array();
     $i18n = new Internationalization('en_US');
     $tpls = $i18n->getTemplate('email_template_group.yaml')->getData();
     foreach ($tpls as $t) {
         // If the email template group specifies an id attribute, remove
         // it for upgrade because we cannot assume that the id slot is
         // available
         unset($t['id']);
         EmailTemplateGroup::create($t, $errors);
     }
     $files = $i18n->getTemplate('file.yaml')->getData();
     foreach ($files as $f) {
         $id = AttachmentFile::create($f, $errors);
         // Ensure the new files are never deleted (attached to Disk)
         $sql = 'INSERT INTO ' . ATTACHMENT_TABLE . ' SET object_id=0, `type`=\'D\', inline=1' . ', file_id=' . db_input($id);
         db_query($sql);
     }
 }
Ejemplo n.º 2
0
 public function savefile($uid, $original_file_path, $original_basename, $file_name = NULL, $file_ext = NULL, $description = NULL)
 {
     if (!file_exists($original_file_path)) {
         return FALSE;
     }
     is_null($file_ext) && ($file_ext = strtolower(pathinfo($original_basename, PATHINFO_EXTENSION)));
     is_null($file_name) && ($file_name = mb_basename($original_basename, '.' . $file_ext));
     //支持中文的basename
     $size = filesize($original_file_path);
     if (!in_array($file_ext, $this->_config['ext'])) {
         return static::UPLOAD_ERR_EXT;
     }
     if ($size > $this->_config['maxsize']) {
         return static::UPLOAD_ERR_MAXSIZE;
     }
     if (empty($size)) {
         return static::UPLOAD_ERR_EMPTY;
     }
     //传文件都耗费了那么多时间,还怕md5?
     $hash = md5_file($original_file_path);
     $file = $this->fileModel->get_byhash($hash, $size);
     if (empty($file)) {
         $new_basename = $this->_get_hash_basename();
         $new_hash_path = $this->get_hash_path($new_basename);
         if (!$this->_save_file($original_file_path, $new_basename)) {
             return static::UPLOAD_ERR_SAVE;
         }
         $file = AttachmentFile::create(['basename' => $new_basename, 'path' => $new_hash_path, 'hash' => $hash, 'size' => $size]);
     } else {
         //已经存在此文件
         @unlink($original_file_path);
     }
     $attachment = $this->create(['afid' => $file->getKey(), 'filename' => $file_name, 'ext' => $file_ext, 'original_basename' => $original_basename, 'description' => $description, 'uid' => $uid]);
     //当前Model更新
     //$this->setRawAttributes($attachment->getAttributes(), true);
     return $this->get($attachment->getKey());
 }