public function Update() { // Check for permission or flood control. // These settings are loaded/saved to the database because we don't want the config file storing non/config information. $Now = time(); $LastTime = Gdn::Get('Garden.Update.LastTimestamp', 0); if ($LastTime + (60 * 60 * 24) > $Now) { // Check for flood control. $Count = Gdn::Get('Garden.Update.Count', 0) + 1; if ($Count > 5) { if (!Gdn::Session()->CheckPermission('Garden.Settings.Manage')) { // We are only allowing an update of 5 times every 24 hours. throw PermissionException(); } } } else { $Count = 1; } Gdn::Set('Garden.Update.LastTimestamp', $Now); Gdn::Set('Garden.Update.Count', $Count); // Run the structure. $UpdateModel = new UpdateModel(); $UpdateModel->RunStructure(); $this->SetData('Success', TRUE); $this->MasterView = 'none'; $this->Render(); }
/** * Run a structure update on the database. * * @since 2.0.? * @access public */ public function Update() { try { // Check for permission or flood control. // These settings are loaded/saved to the database because we don't want the config file storing non/config information. $Now = time(); $LastTime = Gdn::Get('Garden.Update.LastTimestamp', 0); if ($LastTime + 60 * 60 * 24 > $Now) { // Check for flood control. $Count = Gdn::Get('Garden.Update.Count', 0) + 1; if ($Count > 5) { if (!Gdn::Session()->CheckPermission('Garden.Settings.Manage')) { // We are only allowing an update of 5 times every 24 hours. throw PermissionException(); } } } else { $Count = 1; } Gdn::Set('Garden.Update.LastTimestamp', $Now); Gdn::Set('Garden.Update.Count', $Count); } catch (PermissionException $Ex) { return; } catch (Exception $Ex) { } try { // Run the structure. $UpdateModel = new UpdateModel(); $UpdateModel->RunStructure(); $this->SetData('Success', TRUE); } catch (Exception $Ex) { $this->SetData('Success', FALSE); if (Debug()) { throw $Ex; } } if (Gdn::Session()->CheckPermission('Garden.Settings.Manage')) { SaveToConfig('Garden.Version', APPLICATION_VERSION); } if ($Target = $this->Request->Get('Target')) { Redirect($Target); } $this->FireEvent('AfterUpdate'); $this->MasterView = 'empty'; $this->CssClass = 'Home'; $this->Render(); }
public static function update() { $updateModel = new UpdateModel(); $updateModel->prepareForUpdate(); Model::runMigrations(); }
<?php /* * Esta clase actualiza la base de datos mergeando la base de Eventos y Areas de la Municipalidad * * */ include_once 'UpdateModel.php'; /*Comienzo del update*/ $updateModel = new UpdateModel(); $updateModel->updateModel();
/** * Parse an addon's README file. * * @param string $Path The base path to search from. * @return string */ protected function parseReadme($Path) { $ReadmePaths = array('/readme', '/README', '/readme.md', '/README.md', '/readme.txt', '/README.txt'); $Description = ''; // Get the list of potential files to analyze. $Entries = UpdateModel::findFiles($Path, $ReadmePaths); if ($Entries === false) { return ''; } foreach ($Entries as $Entry) { $ReadMeContents = file_get_contents($Entry['Path']); $Description = Gdn_Format::markdown($ReadMeContents); } $FolderPath = substr($Path, 0, -4); Gdn_FileSystem::removeFolder($FolderPath); return $Description; }
/** * Run a structure update on the database. * * It should always be possible to call this method, even if no database tables exist yet. * A working forum database should be built from scratch where none exists. Therefore, * it can have no reliance on existing data calls, or they must be able to fail gracefully. * * @since 2.0.? * @access public */ public function update() { // Check for permission or flood control. // These settings are loaded/saved to the database because we don't want the config file storing non/config information. $Now = time(); $LastTime = 0; $Count = 0; try { $LastTime = Gdn::get('Garden.Update.LastTimestamp', 0); } catch (Exception $Ex) { // We don't have a GDN_UserMeta table yet. Sit quietly and one will appear. } if ($LastTime + 60 * 60 * 24 > $Now) { // Check for flood control. try { $Count = Gdn::get('Garden.Update.Count', 0) + 1; } catch (Exception $Ex) { // Once more we sit, watching the breath. } if ($Count > 5) { if (!Gdn::session()->checkPermission('Garden.Settings.Manage')) { // We are only allowing an update of 5 times every 24 hours. throw permissionException(); } } } else { $Count = 1; } try { Gdn::set('Garden.Update.LastTimestamp', $Now); Gdn::set('Garden.Update.Count', $Count); } catch (Exception $Ex) { // What is a GDN_UserMeta table, really? Suffering. } try { // Run the structure. $UpdateModel = new UpdateModel(); $UpdateModel->runStructure(); $this->setData('Success', true); } catch (Exception $Ex) { $this->setData('Success', false); $this->setData('Error', $Ex->getMessage()); if (Debug()) { throw $Ex; } } if (Gdn::session()->checkPermission('Garden.Settings.Manage')) { saveToConfig('Garden.Version', APPLICATION_VERSION); } if ($Target = $this->Request->get('Target')) { safeRedirect($Target); } $this->fireEvent('AfterUpdate'); $this->MasterView = 'empty'; $this->CssClass = 'Home'; $this->render(); }
/** * Save the addon data. * * @param array $Stub * @param bool|array $Settings Not used; for signature compatibility. * @return bool|Gdn_DataSet|mixed|object|string */ public function save($Stub, $Settings = false) { trace('AddonModel->Save()'); $Session = Gdn::session(); $this->defineSchema(); // Most of the values come from the file itself. if (isset($Stub['Path'])) { $Path = $Stub['Path']; } elseif (val('Checked', $Stub)) { $Addon = $Stub; } elseif (isset($Stub['File'])) { $Path = combinePaths(array(PATH_UPLOADS, $Stub['File'])); } else { if (!$Session->checkPermission('Addons.Addon.Manage') && isset($Stub['Filename'])) { // Only admins can modify plugin attributes without the file. $this->Validation->addValidationResult('Filename', 'ValidateRequired'); return false; } } // Analyze and fix the file. if (!isset($Addon)) { if (isset($Path)) { try { $Addon = UpdateModel::analyzeAddon($Path, false); } catch (Exception $Ex) { $Addon = false; $this->Validation->addValidationResult('File', '@' . $Ex->getMessage()); } if (!is_array($Addon)) { $this->Validation->addValidationResult('File', 'Could not analyze the addon file.'); return false; } $Addon = array_merge($Stub, $Addon); } else { $Addon = $Stub; if (isset($Path)) { $Addon['MD5'] = md5_file($Path); $Addon['FileSize'] = filesize($Path); } } } // Get an existing addon. if (isset($Addon['AddonID'])) { $CurrentAddon = $this->getID($Addon['AddonID'], false, ['GetVersions' => true]); } elseif (isset($Addon['AddonKey']) && isset($Addon['AddonTypeID'])) { $CurrentAddon = $this->getID(array($Addon['AddonKey'], $Addon['AddonTypeID']), false, ['GetVersions' => true]); } else { $CurrentAddon = false; } trace($CurrentAddon, 'CurrentAddon'); $Insert = !$CurrentAddon; if ($Insert) { $this->addInsertFields($Addon); } $this->addUpdateFields($Addon); // always add update fields if (!$this->validate($Addon, $Insert)) { trace('Addon did not validate'); return false; } // Search for the current version. $MaxVersion = false; $CurrentVersion = false; if ($CurrentAddon && isset($Addon['Version'])) { // Search for a current version. foreach ($CurrentAddon['Versions'] as $Index => $Version) { if (isset($Addon['AddonVersionID'])) { if ($Addon['AddonVersionID'] == $Version['AddonVersionID']) { $CurrentVersion = $Version; } } elseif (version_compare($Addon['Version'], $Version['Version']) == 0) { $CurrentVersion = $Version; } // Only check for a current version if the version has been checked. if (!$Version['Checked']) { continue; } if (!$MaxVersion || version_compare($MaxVersion['Version'], $Version['Version'], '<')) { $MaxVersion = $Version; } } } // Save the addon. $Fields = $this->filterSchema($Addon); if ($Insert) { $AddonID = $this->SQL->insert($this->Name, $Fields); // Add the activity. $ActivityModel = new ActivityModel(); $Activity = array('ActivityType' => 'Addon', 'ActivityUserID' => $Fields['InsertUserID'], 'NotifyUserID' => ActivityModel::NOTIFY_PUBLIC, 'HeadlineFormat' => '{ActivityUserID,user} added the <a href="{Url,html}">{Data.Name}</a> addon.', 'Story' => Gdn_Format::html($Fields['Description']), 'Route' => '/addon/' . rawurlencode(self::slug($Fields, false)), 'Data' => array('Name' => $Fields['Name'])); $ActivityModel->save($Activity); } else { $AddonID = val('AddonID', $CurrentAddon); // Only save the addon if it is the current version. if (!$MaxVersion || version_compare($Addon['Version'], $MaxVersion['Version'], '>=')) { trace('Uploaded version is the most recent version.'); $this->SQL->put($this->Name, $Fields, array('AddonID' => $AddonID)); } else { $this->SQL->reset(); } } // Save the version. if ($AddonID && isset($Path) || isset($Addon['File'])) { trace('Saving addon version'); $Addon['AddonID'] = $AddonID; if (isset($Path)) { if (!stringBeginsWith($Path, PATH_UPLOADS . '/addons/')) { // The addon must be copied into the uploads folder. $NewPath = PATH_UPLOADS . '/addons/' . basename($Path); //rename($Path, $NewPath); $Path = $NewPath; $this->_AddonCache = array(); } $File = substr($Path, strlen(PATH_UPLOADS . '/')); $Addon['File'] = $File; } if ($CurrentVersion) { $Addon['AddonVersionID'] = val('AddonVersionID', $CurrentVersion); } // Insert or update the version. $VersionModel = new Gdn_Model('AddonVersion'); $AddonVersionID = $VersionModel->save($Addon); $this->Validation->addValidationResult($VersionModel->validationResults()); if (!$AddonVersionID) { return false; } // Update the current version in the addon. if (!$MaxVersion || version_compare($CurrentAddon['Version'], $Addon['Version'], '<')) { $this->SQL->put($this->Name, array('CurrentAddonVersionID' => $AddonVersionID), array('AddonID' => $AddonID)); } } $this->_AddonCache = array(); return $AddonID; }
die; /*$message = ''; if (!empty($eventos)) { echo('Hay eventos'); $this->dataBase->query(createEventTempTable); $this->dataBase->insertArrayObjects("event_temp_table", $eventos, 200); if ($this->dataBase->query(updateEventTable)) { $message = 'Eventos actualizados satisfactoriamente.'; } else { $message = 'Error al actualizar los eventos.'; } $this->dataBase->query(dropEventTempTable); } else { $message = 'No se obtuvieron eventos de la API de la MGP.'; } return $message;*/ } public function updateSubareas() { $subAreas = $this->apiRequest->getSubareas(); } } $model = new UpdateModel(); $model->updateEvents();