本文整理汇总了PHP中JUpdate::set方法的典型用法代码示例。如果您正苦于以下问题:PHP JUpdate::set方法的具体用法?PHP JUpdate::set怎么用?PHP JUpdate::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JUpdate
的用法示例。
在下文中一共展示了JUpdate::set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
public function update($uids)
{
$result = true;
foreach ($uids as $uid) {
$update = new JUpdate();
$instance = JTable::getInstance('update');
$instance->load($uid);
$update->loadFromXML($instance->detailsurl);
$update->set('extra_query', $instance->extra_query);
// Install sets state and enqueues messages
$res = $this->install($update);
if ($res) {
$instance->delete($uid);
}
$result = $res & $result;
}
// Set the final state
$this->setState('result', $result);
}
示例2: install
/**
* Handles the actual update installation.
*
* @param JUpdate $update An update definition
*
* @return boolean Result of install
*
* @since 1.6
*/
private function install($update)
{
$app = JFactory::getApplication();
if (isset($update->get('downloadurl')->_data)) {
$url = $update->downloadurl->_data;
$extra_query = $update->get('extra_query');
if ($extra_query) {
if (strpos($url, '?') === false) {
$url .= '?';
} else {
$url .= '&';
}
$url .= $extra_query;
}
} else {
JError::raiseWarning('', JText::_('COM_INSTALLER_INVALID_EXTENSION_UPDATE'));
return false;
}
$p_file = JInstallerHelper::downloadPackage($url);
// Was the package downloaded?
if (!$p_file) {
JError::raiseWarning('', JText::sprintf('COM_INSTALLER_PACKAGE_DOWNLOAD_FAILED', $url));
return false;
}
$config = JFactory::getConfig();
$tmp_dest = $config->get('tmp_path');
// Unpack the downloaded package file
$package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file);
// Get an installer instance
$installer = JInstaller::getInstance();
$update->set('type', $package['type']);
// Install the package
if (!$installer->update($package['dir'])) {
// There was an error updating the package
$msg = JText::sprintf('COM_INSTALLER_MSG_UPDATE_ERROR', JText::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type'])));
$result = false;
} else {
// Package updated successfully
$msg = JText::sprintf('COM_INSTALLER_MSG_UPDATE_SUCCESS', JText::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type'])));
$result = true;
}
// Quick change
$this->type = $package['type'];
// Set some model state values
$app->enqueueMessage($msg);
// TODO: Reconfigure this code when you have more battery life left
$this->setState('name', $installer->get('name'));
$this->setState('result', $result);
$app->setUserState('com_installer.message', $installer->message);
$app->setUserState('com_installer.extension_message', $installer->get('extension_message'));
// Cleanup the install files
if (!is_file($package['packagefile'])) {
$config = JFactory::getConfig();
$package['packagefile'] = $config->get('tmp_path') . '/' . $package['packagefile'];
}
JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
return $result;
}
示例3: doInstallUpdate
public function doInstallUpdate($update_row)
{
// Load
$this->out('Loading update #' . $update_row->update_id . '...');
$update = new JUpdate();
$updateRow = JTable::getInstance('update');
$updateRow->load($update_row->update_id);
$update->loadFromXml($updateRow->detailsurl, $this->installer->params->get('minimum_stability', JUpdater::STABILITY_STABLE, 'int'));
$update->set('extra_query', $updateRow->extra_query);
// Download
$tmpPath = $this->config->get('tmp_path');
if (!is_writeable($tmpPath)) {
$tmpPath = JPATH_BASE . '/tmp';
}
$url = $update->downloadurl->_data;
if ($extra_query = $update->get('extra_query')) {
$url .= strpos($url, '?') === false ? '?' : '&';
$url .= $extra_query;
}
$this->out(' - Download ' . $url);
$p_file = JInstallerHelper::downloadPackage($url);
if ($p_file) {
$filePath = $tmpPath . '/' . $p_file;
} else {
$this->out(' - Download Failed, Attempting alternate download method...');
$urlFile = preg_replace('/^.*\\/(.*?)$/', '$1', $url);
$filePath = $tmpPath . '/' . $urlFile;
if ($fileHandle = @fopen($filePath, 'w+')) {
$curl = curl_init($url);
curl_setopt_array($curl, [CURLOPT_URL => $url, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_BINARYTRANSFER => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FILE => $fileHandle, CURLOPT_TIMEOUT => 50, CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)']);
$response = curl_exec($curl);
if ($response === false) {
$this->out(' - Download Failed: ' . curl_error($curl));
return false;
}
} else {
$this->out(' - Download Failed, Error writing ' . $filePath);
return false;
}
}
// Catch Error
if (!is_file($filePath)) {
$this->out(' - Download Failed/ File not found');
return false;
}
// Extracting Package
$this->out(' - Extracting Package...');
$package = JInstallerHelper::unpack($filePath);
if (!$package) {
$this->out(' - Extract Failed');
JInstallerHelper::cleanupInstall($filePath);
return false;
}
// Install the package
$this->out(' - Installing ' . $package['dir'] . '...');
$installer = JInstaller::getInstance();
$update->set('type', $package['type']);
if (!$installer->update($package['dir'])) {
$this->out(' - Update Error');
$result = false;
} else {
$this->out(' - Update Success');
$result = true;
}
// Cleanup the install files
$this->out(' - Cleanup');
JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
// Complete
return $result;
}