public function safeUp()
 {
     $updateDefaults = $this->_updateTwitterCard('defaults');
     $updateOverrides = $this->_updateTwitterCard('overrides');
     SproutSeoPlugin::log('Successfully updated `twitterCard` fields from `summary-large-image` to `summary_large_image`.', LogLevel::Info, true);
     return true;
 }
 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     // $this->addForeignKey('sproutseo_defaults', 'id', 'assetfiles', 'id');
     // $this->addForeignKey('sproutseo_overrides', 'id', 'assetfiles', 'id');
     SproutSeoPlugin::log('Added FK to assetfiles table.', LogLevel::Info, true);
     // return true and let craft know its done
     return true;
 }
 /**
  * @return bool
  */
 public function safeUp()
 {
     $tableName = 'sproutseo_redirects';
     if (!craft()->db->tableExists($tableName)) {
         SproutSeoPlugin::log("Creating the {$tableName} table.");
         craft()->db->createCommand()->createTable($tableName, array('id' => array('column' => ColumnType::Int, 'null' => false), 'oldUrl' => array('column' => ColumnType::Varchar, 'null' => false), 'newUrl' => array('column' => ColumnType::Varchar, 'null' => false), 'method' => array('column' => 'int(10)', 'null' => false), 'regex' => array('column' => ColumnType::TinyInt, 'length' => 1, 'null' => false, 'default' => 0, 'unsigned' => true), 'dateCreated' => array('column' => ColumnType::DateTime, 'null' => false), 'dateUpdated' => array('column' => ColumnType::DateTime, 'null' => false), 'uid' => array('column' => 'char(36)', 'null' => false, 'default' => '0')), null, true, false);
         craft()->db->createCommand()->addPrimaryKey($tableName, 'id');
         craft()->db->createCommand()->createIndex($tableName, 'id');
         craft()->db->createCommand()->addForeignKey($tableName, 'id', 'elements', 'id', 'CASCADE');
         SproutSeoPlugin::log("Finished creating the {$tableName} table.");
     } else {
         SproutSeoPlugin::log("The {$tableName} table already exists", LogLevel::Info, true);
     }
     return true;
 }
 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     $overridesTable = 'sproutseo_overrides';
     if (!craft()->db->columnExists($overridesTable, 'locale')) {
         $this->addColumnAfter($overridesTable, 'locale', array('column' => ColumnType::Locale, 'required' => true), 'entryId');
         SproutSeoPlugin::log("Created the column `locale` in `{$overridesTable}`.", LogLevel::Info, true);
     } else {
         SproutSeoPlugin::log("Column `locale` already existed in `{$overridesTable}`.", LogLevel::Info, true);
     }
     MigrationHelper::dropIndexIfExists($overridesTable, 'entryId');
     SproutSeoPlugin::log("Index `entryId` dropped from `{$overridesTable}`.", LogLevel::Info, true);
     craft()->db->createCommand()->createIndex($overridesTable, 'entryId, locale', array('entryId', 'locale'), true);
     SproutSeoPlugin::log("Composite index `localeAndEntryId` created on `{$overridesTable}`.", LogLevel::Info, true);
     return true;
 }
 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     // The Table you wish to add. 'craft_' prefix will be added automatically.
     $tableName = 'sproutseo_sitemap';
     // If our Sitemap table already exists, get rid of it
     if (craft()->db->tableExists($tableName)) {
         SproutSeoPlugin::log("Dropping the `{$tableName}` table.", LogLevel::Info, true);
         $this->dropTableIfExists($tableName);
     }
     SproutSeoPlugin::log("Creating the `{$tableName}` table.", LogLevel::Info, true);
     // Review Column Types in craft/app/enums/ColumnType.php
     $this->createTable($tableName, array('sectionId' => array('column' => ColumnType::Int), 'url' => array('column' => ColumnType::Varchar), 'priority' => array('column' => ColumnType::Decimal, 'default' => '0.5', 'required' => true, 'maxLength' => 2, 'decimals' => 1), 'changeFrequency' => array('column' => ColumnType::Varchar, 'default' => 'weekly', 'required' => true, 'maxLength' => 7), 'enabled' => array('column' => ColumnType::Bool, 'default' => false, 'required' => true), 'ping' => array('column' => ColumnType::Bool, 'default' => false, 'required' => true)));
     $this->createIndex($tableName, 'sectionId', true);
     $this->addForeignKey($tableName, 'sectionId', 'sections', 'id', 'CASCADE');
     return true;
 }
 private function _addColumnsAfter($newColumns, $afterColumnHandle)
 {
     // specify the table name here
     $tableName = 'sproutseo_overrides';
     // this is a foreach loop, enough said
     foreach ($newColumns as $columnName => $columnType) {
         // check if the column does NOT exist
         if (!craft()->db->columnExists($tableName, $columnName)) {
             $this->addColumnAfter($tableName, $columnName, array('column' => $columnType, 'null' => false), $afterColumnHandle);
             // log that we created the new column
             SproutSeoPlugin::log("Created the `{$columnName}` in the `{$tableName}` table.", LogLevel::Info, true);
         } else {
             // tell craft that we couldn't create the column as it alredy exists.
             SproutSeoPlugin::log("Column `{$columnName}` already exists in the `{$tableName}` table.", LogLevel::Info, true);
         }
     }
 }
 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     // The Table you wish to add. 'craft_' prefix will be added automatically.
     $oldTableName = 'sproutseo_fallbacks';
     $newTableName = 'sproutseo_templates';
     if (!craft()->db->tableExists($newTableName)) {
         SproutSeoPlugin::log("New table `{$newTableName}` doesn't exist.", LogLevel::Info, true);
         if (craft()->db->tableExists($oldTableName)) {
             SproutSeoPlugin::log("Old table `{$oldTableName}` does exist.", LogLevel::Info, true);
             SproutSeoPlugin::log("Renaming the `{$oldTableName}` table.", LogLevel::Info, true);
             // Rename table
             $this->renameTable($oldTableName, $newTableName);
             SproutSeoPlugin::log("`{$oldTableName}` table has been renamed to `{$newTableName}`.", LogLevel::Info, true);
         }
     }
     return true;
 }
 public function safeup()
 {
     // The Table you wish to add. 'craft_' prefix will be added automatically.
     $oldTableName = 'sproutseo_templates';
     $newTableName = 'sproutseo_defaults';
     if (!craft()->db->tableExists($newTableName)) {
         SproutSeoPlugin::log("New table `{$newTableName}` doesn't exist.", LogLevel::Info, true);
         if (craft()->db->tableExists($oldTableName)) {
             MigrationHelper::dropIndexIfExists('sproutseo_templates', array('name', 'handle'), true);
             SproutSeoPlugin::log("Old table `{$oldTableName}` does exist.", LogLevel::Info, true);
             SproutSeoPlugin::log("Renaming the `{$oldTableName}` table.", LogLevel::Info, true);
             // Rename table
             $this->renameTable($oldTableName, $newTableName);
             $this->createIndex('sproutseo_defaults', 'name,handle', true);
             SproutSeoPlugin::log("`{$oldTableName}` table has been renamed to `{$newTableName}`.", LogLevel::Info, true);
         }
     }
     return true;
 }
 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     // specify the table name here
     $tableName = 'sproutseo_templates';
     // specify columns and AttributeType
     $newColumns = array('twitterCard' => ColumnType::Varchar, 'twitterImage' => ColumnType::Varchar, 'twitterPlayer' => ColumnType::Varchar, 'twitterPlayerStream' => ColumnType::Varchar, 'twitterPlayerStreamContentType' => ColumnType::Varchar, 'twitterPlayerWidth' => ColumnType::Varchar, 'twitterPlayerHeight' => ColumnType::Varchar);
     // this is a foreach loop, enough said
     foreach ($newColumns as $columnName => $columnType) {
         // check if the column does NOT exist
         if (!craft()->db->columnExists($tableName, $columnName)) {
             // add the column to the table
             $this->addColumn($tableName, $columnName, array('column' => $columnType, 'required' => false));
             // log that we created the new column
             SproutSeoPlugin::log("Created the `{$columnName}` in the `{$tableName}` table.", LogLevel::Info, true);
         } else {
             // tell craft that we couldn't create the column as it alredy exists.
             SproutSeoPlugin::log("Column `{$columnName}` already exists in the `{$tableName}` table.", LogLevel::Info, true);
         }
     }
     // return true and let craft know its done
     return true;
 }
 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     // specify the table name here
     $tableName = 'sproutseo_templates';
     // specify columns and AttributeType
     $newColumns = array('globalFallback' => ColumnType::TinyInt);
     // this is a foreach loop, enough said
     foreach ($newColumns as $columnName => $columnType) {
         // check if the column does NOT exist
         if (!craft()->db->columnExists($tableName, $columnName)) {
             // add the column to the table
             $this->addColumnAfter($tableName, $columnName, array('column' => $columnType, 'required' => false), 'handle');
             // log that we created the new column
             SproutSeoPlugin::log("Created the `{$columnName}` in the `{$tableName}` table.", LogLevel::Info, true);
         } else {
             // tell craft that we couldn't create the column as it alredy exists.
             SproutSeoPlugin::log("Column `{$columnName}` already exists in the `{$tableName}` table.", LogLevel::Info, true);
         }
     }
     // return true and let craft know its done
     return true;
 }
 /**
  * @return string
  */
 public function getVersion()
 {
     return $this->plugin->getVersion();
 }
 /**
  * Returns all URLs for a given sitemap or the rendered sitemap itself
  *
  * @param array|null $options
  *
  * @throws Exception
  * @return array|string
  */
 public function getSitemap(array $options = null)
 {
     $urls = array();
     $enabledSections = craft()->db->createCommand()->select('*')->from('sproutseo_sitemap')->where('enabled = 1')->andWhere('sectionId is not null')->queryAll();
     // Fetching settings for each enabled section in Sprout SEO
     foreach ($enabledSections as $key => $sitemapSettings) {
         // Fetching all enabled locales
         foreach (craft()->i18n->getSiteLocales() as $locale) {
             $criteria = craft()->elements->getCriteria(ElementType::Entry);
             $criteria->limit = null;
             $criteria->status = 'live';
             $criteria->locale = $locale->id;
             $criteria->sectionId = $sitemapSettings['sectionId'];
             /**
              * @var $entries EntryModel[]
              *
              * Fetching all entries enabled for the current locale
              */
             $entries = $criteria->find();
             foreach ($entries as $entry) {
                 // @todo ensure that this check/logging is absolutely necessary
                 // Catch null URLs, log them, and prevent them from being output to the sitemap
                 if (is_null($entry->getUrl())) {
                     SproutSeoPlugin::log('Entry ID ' . $entry->id . " does not have a URL.", LogLevel::Warning, true);
                     continue;
                 }
                 // Adding each location indexed by its id
                 $urls[$entry->id][] = array('id' => $entry->id, 'url' => $entry->getUrl(), 'locale' => $locale->id, 'modified' => $entry->dateUpdated->format('Y-m-d\\Th:m:s\\Z'), 'priority' => $sitemapSettings['priority'], 'frequency' => $sitemapSettings['changeFrequency']);
             }
         }
     }
     // Fetching all custom pages define in Sprout SEO
     $customUrls = craft()->db->createCommand()->select('url, priority, changeFrequency as frequency, dateUpdated')->from('sproutseo_sitemap')->where('enabled = 1')->andWhere('url is not null')->queryAll();
     foreach ($customUrls as $customEntry) {
         // Adding each custom location indexed by its URL
         $modified = new DateTime($customEntry['dateUpdated']);
         $customEntry['modified'] = $modified->format('Y-m-d\\Th:m:s\\Z');
         $urls[$customEntry['url']] = craft()->config->parseEnvironmentString($customEntry);
     }
     $urls = $this->getLocalizedSitemapStructure($urls);
     // Rendering the template and passing in received options
     $path = craft()->path->getTemplatesPath();
     craft()->path->setTemplatesPath(dirname(__FILE__) . '/../templates/');
     $source = craft()->templates->render('_special/sitemap', array('entries' => $urls, 'options' => is_array($options) ? $options : array()));
     craft()->path->setTemplatesPath($path);
     return TemplateHelper::getRaw($source);
 }