本文整理匯總了PHP中FileModel::objects方法的典型用法代碼示例。如果您正苦於以下問題:PHP FileModel::objects方法的具體用法?PHP FileModel::objects怎麽用?PHP FileModel::objects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類FileModel
的用法示例。
在下文中一共展示了FileModel::objects方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: run
function run($args, $options)
{
Bootstrap::connect();
osTicket::start();
switch ($args['action']) {
case 'backends':
// List configured backends
foreach (FileStorageBackend::allRegistered() as $char => $bk) {
print "{$char} -- {$bk::$desc} ({$bk})\n";
}
break;
case 'list':
// List files matching criteria
// ORM would be nice!
$files = FileModel::objects();
$this->_applyCriteria($options, $files);
foreach ($files as $f) {
printf("% 5d %s % 8d %s % 16s %s\n", $f->id, $f->bk, $f->size, $f->created, $f->type, $f->name);
if ($f->attrs) {
printf(" %s\n", $f->attrs);
}
}
break;
case 'dump':
$files = FileModel::objects();
$this->_applyCriteria($options, $files);
if ($files->count() != 1) {
$this->fail('Criteria must select exactly 1 file');
}
if (($f = AttachmentFile::lookup($files[0]->id)) && ($bk = $f->open())) {
$bk->passthru();
}
break;
case 'load':
// Load file content from STDIN
$files = FileModel::objects();
$this->_applyCriteria($options, $files);
if ($files->count() != 1) {
$this->fail('Criteria must select exactly 1 file');
}
$f = AttachmentFile::lookup($files[0]->id);
try {
if ($bk = $f->open()) {
$bk->unlink();
}
} catch (Exception $e) {
}
if ($options['to']) {
$bk = FileStorageBackend::lookup($options['to'], $f);
} else {
// Use the system default
$bk = AttachmentFile::getBackendForFile($f);
}
$type = false;
$signature = '';
$finfo = new finfo(FILEINFO_MIME_TYPE);
if ($options['file'] && $options['file'] != '-') {
if (!file_exists($options['file'])) {
$this->fail($options['file'] . ': Cannot open file');
}
if (!$bk->upload($options['file'])) {
$this->fail('Unable to upload file contents to backend');
}
$type = $finfo->file($options['file']);
list(, $signature) = AttachmentFile::_getKeyAndHash($options['file'], true);
} else {
$stream = fopen('php://stdin', 'rb');
while ($block = fread($stream, $bk->getBlockSize())) {
if (!$bk->write($block)) {
$this->fail('Unable to send file contents to backend');
}
if (!$type) {
$type = $finfo->buffer($block);
}
}
if (!$bk->flush()) {
$this->fail('Unable to commit file contents to backend');
}
}
// TODO: Update file metadata
$sql = 'UPDATE ' . FILE_TABLE . ' SET bk=' . db_input($bk->getBkChar()) . ', created=CURRENT_TIMESTAMP' . ', type=' . db_input($type) . ', signature=' . db_input($signature) . ' WHERE id=' . db_input($f->getId());
if (!db_query($sql) || db_affected_rows() != 1) {
$this->fail('Unable to update file metadata');
}
$this->stdout->write("Successfully saved contents\n");
break;
case 'migrate':
if (!$options['to']) {
$this->fail('Please specify a target backend for migration');
}
if (!FileStorageBackend::isRegistered($options['to'])) {
$this->fail('Target backend is not installed. See `backends` action');
}
$files = FileModel::objects();
$this->_applyCriteria($options, $files);
$count = 0;
foreach ($files as $m) {
$f = AttachmentFile::lookup($m->id);
if ($f->getBackend() == $options['to']) {
continue;
//.........這裏部分代碼省略.........
示例2: run
function run($args, $options)
{
Bootstrap::connect();
osTicket::start();
switch ($args['action']) {
case 'backends':
// List configured backends
foreach (FileStorageBackend::allRegistered() as $char => $bk) {
print "{$char} -- {$bk::$desc} ({$bk})\n";
}
break;
case 'list':
// List files matching criteria
// ORM would be nice!
$files = FileModel::objects();
$this->_applyCriteria($options, $files);
foreach ($files as $f) {
printf("% 5d %s % 8d %s % 16s %s\n", $f->id, $f->bk, $f->size, $f->created, $f->type, $f->name);
if ($f->attrs) {
printf(" %s\n", $f->attrs);
}
}
break;
case 'dump':
$files = FileModel::objects();
$this->_applyCriteria($options, $files);
if ($files->count() != 1) {
$this->fail('Criteria must select exactly 1 file');
}
if (($f = AttachmentFile::lookup($files[0]->id)) && ($bk = $f->open())) {
$bk->passthru();
}
break;
case 'load':
// Load file content from STDIN
$files = FileModel::objects();
$this->_applyCriteria($options, $files);
if ($files->count() != 1) {
$this->fail('Criteria must select exactly 1 file');
}
$f = AttachmentFile::lookup($files[0]->id);
try {
if ($bk = $f->open()) {
$bk->unlink();
}
} catch (Exception $e) {
}
if ($options['to']) {
$bk = FileStorageBackend::lookup($options['to'], $f);
} else {
// Use the system default
$bk = AttachmentFile::getBackendForFile($f);
}
$type = false;
$signature = '';
$finfo = new finfo(FILEINFO_MIME_TYPE);
if ($options['file'] && $options['file'] != '-') {
if (!file_exists($options['file'])) {
$this->fail($options['file'] . ': Cannot open file');
}
if (!$bk->upload($options['file'])) {
$this->fail('Unable to upload file contents to backend');
}
$type = $finfo->file($options['file']);
list(, $signature) = AttachmentFile::_getKeyAndHash($options['file'], true);
} else {
$stream = fopen('php://stdin', 'rb');
while ($block = fread($stream, $bk->getBlockSize())) {
if (!$bk->write($block)) {
$this->fail('Unable to send file contents to backend');
}
if (!$type) {
$type = $finfo->buffer($block);
}
}
if (!$bk->flush()) {
$this->fail('Unable to commit file contents to backend');
}
}
// TODO: Update file metadata
$sql = 'UPDATE ' . FILE_TABLE . ' SET bk=' . db_input($bk->getBkChar()) . ', created=CURRENT_TIMESTAMP' . ', type=' . db_input($type) . ', signature=' . db_input($signature) . ' WHERE id=' . db_input($f->getId());
if (!db_query($sql) || db_affected_rows() != 1) {
$this->fail('Unable to update file metadata');
}
$this->stdout->write("Successfully saved contents\n");
break;
case 'migrate':
if (!$options['to']) {
$this->fail('Please specify a target backend for migration');
}
if (!FileStorageBackend::isRegistered($options['to'])) {
$this->fail('Target backend is not installed. See `backends` action');
}
$files = FileModel::objects();
$this->_applyCriteria($options, $files);
$count = 0;
foreach ($files as $m) {
$f = AttachmentFile::lookup($m->id);
if ($f->getBackend() == $options['to']) {
continue;
//.........這裏部分代碼省略.........