コード例 #1
0
 /**
  * @param      $uid
  * @param      $handle
  * @param bool $dbBackupPath
  *
  * @throws Exception
  * @return array
  */
 public function updateDatabase($uid, $handle, $dbBackupPath = false)
 {
     Craft::log('Starting to update the database.', LogLevel::Info, true);
     try {
         $updater = new Updater();
         if ($handle == 'craft') {
             Craft::log('Craft wants to update the database.', LogLevel::Info, true);
             $updater->updateDatabase($uid, $dbBackupPath);
             Craft::log('Craft is done updating the database.', LogLevel::Info, true);
         } else {
             $plugin = craft()->plugins->getPlugin($handle);
             if ($plugin) {
                 Craft::log('The plugin, ' . $plugin->getName() . ' wants to update the database.', LogLevel::Info, true);
                 $updater->updateDatabase($uid, $dbBackupPath, $plugin);
                 Craft::log('The plugin, ' . $plugin->getName() . ' is done updating the database.', LogLevel::Info, true);
             } else {
                 Craft::log('Cannot find a plugin with the handle ' . $handle . ' or it is not enabled, therefore it cannot update the database.', LogLevel::Error);
                 throw new Exception(Craft::t('Cannot find an enabled plugin with the handle {handle}.', array('handle' => $handle)));
             }
         }
         return array('success' => true);
     } catch (\Exception $e) {
         return array('success' => false, 'message' => $e->getMessage());
     }
 }