function copyAttachments($source_id, $target_id, $fkTableName) { $f_parts = null; $destFPath = null; $mangled_fname = ''; $status_ok = false; $repo_type = config_get('repositoryType'); $repo_path = config_get('repositoryPath') . DIRECTORY_SEPARATOR; $attachments = $this->getAttachmentInfosFor($source_id, $fkTableName); if (count($attachments) > 0) { foreach ($attachments as $key => $value) { $file_contents = null; $f_parts = explode(DIRECTORY_SEPARATOR, $value['file_path']); $mangled_fname = $f_parts[count($f_parts) - 1]; if ($repo_type == TL_REPOSITORY_TYPE_FS) { $destFPath = $this->buildRepositoryFilePath($mangled_fname, $table_name, $target_id); $status_ok = copy($repo_path . $value['file_path'], $destFPath); } else { $file_contents = $this->getAttachmentContentFromDB($value['id']); $status_ok = sizeof($file_contents); } if ($status_ok) { $attachmentMgr = new tlAttachment(); $attachmentMgr->create($target_id, $fkTableName, $value['file_name'], $destFPath, $file_contents, $value['file_type'], $value['file_size'], $value['title']); $attachmentMgr->writeToDB($this->db); } } } }
function buildAttachSetup($id, $options = null) { $opt = array('show_mode' => null); $opt = array_merge($opt, (array) $options); $systemWideCfg = config_get('attachments'); $info = $this->getAttachmentInfos($id); $cfg = tlAttachment::getGuiCfg(); $cfg->display = $systemWideCfg->enabled && !is_null($info); $cfg->uploadEnabled = $cfg->showUploadBtn && $opt['show_mode'] != 'readonly'; $dummy = $this->attachmentRepository->checkRepositoryStatus(); $cfg->enabled = $dummy['enabled']; return array($info, $cfg); }