本文整理汇总了PHP中Bootstrap::connect方法的典型用法代码示例。如果您正苦于以下问题:PHP Bootstrap::connect方法的具体用法?PHP Bootstrap::connect怎么用?PHP Bootstrap::connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bootstrap
的用法示例。
在下文中一共展示了Bootstrap::connect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
function run($args, $options) {
Bootstrap::connect();
switch ($args['action']) {
case 'import':
if (!$options['file'])
$this->fail('Import CSV file required!');
elseif (!($this->stream = fopen($options['file'], 'rb')))
$this->fail("Unable to open input file [{$options['file']}]");
//Read the header (if any)
if (($data = fgetcsv($this->stream, 1000, ","))) {
if (strcasecmp($data[0], 'name'))
fseek($this->stream, 0); // We don't have an header!
else;
// TODO: process the header here to figure out the columns
// for now we're assuming one column of Name
}
while (($data = fgetcsv($this->stream, 1000, ",")) !== FALSE) {
if (!$data[0])
$this->stderr->write('Invalid data format: Name
required');
elseif (!Organization::fromVars(array('name' => $data[0], 'email')))
$this->stderr->write('Unable to import record: '.print_r($data, true));
}
break;
case 'export':
$stream = $options['file'] ?: 'php://stdout';
if (!($this->stream = fopen($stream, 'c')))
$this->fail("Unable to open output file [{$options['file']}]");
fputcsv($this->stream, array('Name'));
foreach (Organization::objects() as $org)
fputcsv($this->stream,
array((string) $org->getName()));
break;
default:
$this->stderr->write('Unknown action!');
}
@fclose($this->stream);
}
示例2: run
function run($args, $options) {
$stream = $options['stream'];
if ($options['compress']) $stream = "compress.zlib://$stream";
if (!($this->stream = fopen($stream, 'rb'))) {
$this->stderr->write('Unable to open input stream');
die();
}
if (!$this->verify_header())
die('Unable to verify backup header');
Bootstrap::connect();
$class = 'Importer_' . $this->header[1];
$importer = new $class($this);
while ($importer->import_table());
@fclose($this->stream);
}
示例3: run
function run($args, $options) {
Bootstrap::connect();
switch ($args['action']) {
case 'import':
// Properly detect Macintosh style line endings
ini_set('auto_detect_line_endings', true);
if (!$options['file'])
$this->fail('CSV file to import users from is required!');
elseif (!($this->stream = fopen($options['file'], 'rb')))
$this->fail("Unable to open input file [{$options['file']}]");
$extras = array();
if ($options['org']) {
if (!($org = Organization::lookup($options['org'])))
$this->fail($options['org'].': Unknown organization ID');
$extras['org_id'] = $options['org'];
}
$status = User::importCsv($this->stream, $extras);
if (is_numeric($status))
$this->stderr->write("Successfully imported $status clients\n");
else
$this->fail($status);
break;
case 'export':
$stream = $options['file'] ?: 'php://stdout';
if (!($this->stream = fopen($stream, 'c')))
$this->fail("Unable to open output file [{$options['file']}]");
fputcsv($this->stream, array('Name', 'Email'));
foreach (User::objects() as $user)
fputcsv($this->stream,
array((string) $user->getName(), $user->getEmail()));
break;
default:
$this->stderr->write('Unknown action!');
}
@fclose($this->stream);
}
示例4: 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;
//.........这里部分代码省略.........
示例5: die
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
#Disable direct access.
if (isset($_SERVER['SCRIPT_NAME']) && !strcasecmp(basename($_SERVER['SCRIPT_NAME']), basename(__FILE__))) {
die('kwaheri rafiki!');
}
require 'bootstrap.php';
Bootstrap::loadConfig();
Bootstrap::defineTables(TABLE_PREFIX);
Bootstrap::i18n_prep();
Bootstrap::loadCode();
Bootstrap::connect();
if (!($ost = osTicket::start()) || !($cfg = $ost->getConfig())) {
Bootstrap::croak(__('Unable to load config info from DB. Get tech support.'));
}
//Init
$session = $ost->getSession();
//System defaults we might want to make global//
#pagenation default - user can override it!
define('DEFAULT_PAGE_LIMIT', $cfg->getPageSize() ? $cfg->getPageSize() : 25);
#Cleanup magic quotes crap.
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
$_POST = Format::strip_slashes($_POST);
$_GET = Format::strip_slashes($_GET);
$_REQUEST = Format::strip_slashes($_REQUEST);
}
// extract system messages
示例6: 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;
//.........这里部分代码省略.........