/** * Called when migrating up. */ public function up() { //delete open social table dbexec('DROP TABLE #__opensocial_profiles'); //delete legacy com_cache and com_opensocial dbexec('DELETE FROM #__components WHERE `option` = \'com_cache\' OR `option` = \'com_opensocial\' '); //some clean up dbexec('DELETE FROM #__components WHERE name = "" '); //fix broken menu link dbexec('UPDATE #__components SET `admin_menu_link` = \'option=com_mailer\' WHERE `option` = \'com_mailer\' '); //Delete legacy plugins dbexec('DELETE FROM #__plugins WHERE `element` IN ( \'ptag\', \'syntax\', \'opensocial\', \'mtupgrade\', \'usertype\' ) '); //remove anahita from nodes and edges table names if (!dbexists('SHOW TABLES LIKE "#__nodes"')) { dbexec('RENAME TABLE #__anahita_nodes TO #__nodes'); } //add pinned field to the nodes table if (!dbexists('SHOW COLUMNS FROM #__nodes LIKE "pinned"')) { dbexec('ALTER TABLE #__nodes ADD `pinned` TINYINT(1) NOT NULL DEFAULT \'0\' AFTER `enabled`'); } //add github gist plugin dbexec("INSERT INTO `#__plugins` (`name`, `element`, `folder`, `access`, `ordering`, `published`, `iscore`, `client_id`, `checked_out`, `checked_out_time`, `params`) VALUES ('Content Filter - Medium', 'medium', 'contentfilter', 0, 1, 1, 0, 0, 0, '0000-00-00 00:00:00', '')"); //remove the photo plugin dbexec("DELETE FROM #__plugins WHERE `element` = 'photo' "); //remove the migrator_migrations table if exists dbexec('DROP TABLE #__migrator_migrations'); //some of the plugins are core plugins dbexec("UPDATE jos_plugins SET iscore = 1 WHERE element IN ('joomla', 'gist', 'medium', 'link', 'video', 's3')"); }
/** * Called when migrating up. */ public function up() { dbexec('delete from jos_components where `option` IN ("com_installer","com_bazaar","com_tagmeta")'); dbexec('delete from jos_components where `option` IS NULL OR `option` = ""'); dbexec('update jos_components set admin_menu_link ="" where `option` IN ("com_search","com_todos","com_pages","com_html","com_invites")'); ///remove privacy_read_mode. some installation may still have it try { dbexec('alter table jos_anahita_nodes drop column `privacy_read_mode`'); } catch (Exception $e) { } dbexec('DROP TABLE IF EXISTS `jos_core_log_items`'); dbexec('DROP TABLE IF EXISTS `jos_core_log_searches`'); dbexec('DROP TABLE IF EXISTS `jos_stats_agents`'); dbexec('DROP TABLE IF EXISTS `jos_tagmeta`'); dbexec('DROP TABLE IF EXISTS `jos_migration_backlinks`'); dbexec('DROP TABLE IF EXISTS `jos_migrations`'); dbexec("DELETE FROM `jos_modules_menu` WHERE `moduleid` IN (SELECT `id` FROM `jos_modules` WHERE `module` IN ('mod_bazaar','mod_footer','mod_login','mod_rokquicklinks'))"); dbexec("DELETE FROM `jos_modules` WHERE `module` IN ('mod_bazaar','mod_footer','mod_login','mod_rokquicklinks')"); $people = dbfetch('select id,person_username AS username,person_userid AS userid from jos_anahita_nodes where type like "ComActorsDomainEntityActor,ComPeopleDomainEntityPerson,com:people.domain.entity.person" and person_username NOT REGEXP "^[A-Za-z0-9][A-Za-z0-9_-]*$"'); foreach ($people as $person) { $username = $person['username']; $clean = $username = preg_replace('/(\\s|\\.|(@\\w+))+/', '', $username); //add a randome number until the username becomes unique while (dbexists("select id from jos_users where username like '{$username}'")) { $username = $clean . rand(0, 100); } dbexec("update jos_anahita_nodes set person_username = '******' where id = {$person['id']}"); dbexec("update jos_users set username = '******' where id = {$person['userid']}"); } }
/** * Called when migrating up. */ public function up() { if (!dbexists('SHOW TABLES LIKE "#__edges"')) { dbexec('RENAME TABLE #__anahita_edges TO #__edges'); } dbexec('DELETE FROM #__edges WHERE node_a_id = node_b_id'); }
/** * Called when migrating up. */ public function up() { //add html component if not already in if (!dbexists('SELECT id FROM #__components WHERE `option` = "com_html"')) { $this[] = "INSERT INTO `#__components` VALUES(NULL, 'Html', 'option=com_html', 0, 0, 'option=com_html', 'Html', 'com_html', 0, 'js/ThemeOffice/component.png', 1, '', 1)"; } $this[] = "UPDATE #__components SET admin_menu_link='option=com_html', admin_menu_alt='Html', admin_menu_img='js/ThemeOffice/component.png' WHERE `option` = 'com_html'"; $this[] = "DELETE FROM #__plugins WHERE folder IN ('content','editors','editors-xtd') OR element = 'mtupgrade'"; }
/** * Called when migrating up. */ public function up() { //delete a legacy record dbexec('DELETE FROM #__components WHERE `option` = \'com_content\' '); //add the mention tag contentfilter dbexec('INSERT INTO #__plugins (`name`,`element`,`folder`,`iscore`,`published`) VALUES (\'Mention\', \'mention\',\'contentfilter\',1,1)'); if (!dbexists('SHOW TABLES LIKE "#__edges"')) { dbexec('RENAME TABLE #__anahita_edges TO #__edges'); } //changing the hashtag class name to tag dbexec('UPDATE #__edges SET `type` = REPLACE(`type`, \'ComHashtagsDomainEntityAssociation,com:hashtags.domain.entity.association\', \'ComTagsDomainEntityTag,ComHashtagsDomainEntityTag,com:hashtags.domain.entity.tag\') WHERE type LIKE \'%com:hashtags.domain.entity%\' '); }
/** * Called when migrating up. */ public function up() { //remove anahita from nodes and edges table names if (!dbexists('SHOW TABLES LIKE "#__nodes"')) { dbexec('RENAME TABLE #__anahita_nodes TO #__nodes'); } if (!dbexists('SHOW TABLES LIKE "#__edges"')) { dbexec('RENAME TABLE #__anahita_edges TO #__edges'); } if (!dbexists('SHOW COLUMNS FROM #__nodes LIKE "cover_filename"')) { dbexec('ALTER TABLE #__nodes ADD `cover_filename` VARCHAR(255) NULL AFTER `filesize`, ADD `cover_filesize` INT(11) NULL AFTER `cover_filename`, ADD `cover_mimetype` VARCHAR(100) NULL AFTER `cover_filesize`'); } }
/** * Called when migrating up. */ public function up() { //remove anahita from nodes and edges table names if (!dbexists('SHOW TABLES LIKE "#__nodes"')) { dbexec('RENAME TABLE #__anahita_nodes TO #__nodes'); } if (!dbexists('SHOW TABLES LIKE "#__edges"')) { dbexec('RENAME TABLE #__anahita_edges TO #__edges'); } //migrate users usertype dbexec('UPDATE #__users SET `usertype`=\'registered\' WHERE `usertype` NOT LIKE \'%admin%\' '); dbexec('UPDATE #__users SET `usertype`=\'administrator\' WHERE `usertype`=\'Administrator\' '); dbexec('UPDATE #__users SET `usertype`=\'super-administrator\' WHERE `usertype`=\'Super Administrator\' '); dbexec('ALTER TABLE #__users DROP COLUMN `gid` '); dbexec('ALTER TABLE #__users DROP COLUMN `sendEmail` '); //migrate people usertype dbexec('UPDATE #__nodes SET `person_usertype`=\'registered\' WHERE `person_usertype` NOT LIKE \'%admin%\' '); dbexec('UPDATE #__nodes SET `person_usertype`=\'administrator\' WHERE `person_usertype`=\'Administrator\' '); dbexec('UPDATE #__nodes SET `person_usertype`=\'super-administrator\' WHERE `person_usertype`=\'Super Administrator\' '); //migrate session table dbexec('ALTER TABLE #__session DROP COLUMN `gid` '); //drop legacy tables dbexec('DROP TABLE #__core_acl_aro'); dbexec('DROP TABLE #__core_acl_aro_groups'); dbexec('DROP TABLE #__core_acl_aro_map'); dbexec('DROP TABLE #__core_acl_aro_sections'); dbexec('DROP TABLE #__core_acl_groups_aro_map'); dbexec('DROP TABLE #__groups'); //legacy component cleanup dbexec('DELETE FROM #__components WHERE `option` IN (\'com_users\', \'com_user\') '); dbexec('UPDATE #__components SET `admin_menu_link`=\'option=com_people\', `admin_menu_alt`=\'People\', `admin_menu_img`=\'js/ThemeOffice/component.png\' WHERE `option`=\'com_people\' '); dbexec('ALTER TABLE #__nodes MODIFY `enabled` tinyint(1) NOT NULL DEFAULT 0'); dbexec('ALTER TABLE #__nodes MODIFY `is_default` tinyint(1) NOT NULL DEFAULT 0'); dbexec('UPDATE #__nodes SET `story_subject_id` = `created_by` WHERE `story_subject_id` = `story_target_id` AND `name` = \'actor_follow\''); dbexec('UPDATE #__nodes SET `enabled`=1, `access` = \'admins\' WHERE `type` LIKE \'%com:people.domain.entity.person\' AND `enabled` = 0'); }
/** * Called when migrating up. */ public function up() { //looks like these two didn't work in previous migrations dbexec('DROP TABLE #__content_rating'); dbexec("DELETE FROM #__components WHERE `option` IN ('com_media', 'com_menus', 'com_modules')"); //add github gist plugin dbexec("INSERT INTO `#__plugins` (`id`, `name`, `element`, `folder`, `access`, `ordering`, `published`, `iscore`, `client_id`, `checked_out`, `checked_out_time`, `params`) VALUES (49, 'Content Filter - GithubGist', 'gist', 'contentfilter', 0, 0, 0, 0, 0, 0, '0000-00-00 00:00:00', '')"); //remove the syntax plugin dbexec("DELETE FROM #__plugins WHERE `element` IN ('syntax', 'ptag') "); //remove anahita from nodes and edges table names if (!dbexists('SHOW TABLES LIKE "#__nodes"')) { dbexec('RENAME TABLE #__anahita_nodes TO #__nodes'); } if (!dbexists('SHOW TABLES LIKE "#__edges"')) { dbexec('RENAME TABLE #__anahita_edges TO #__edges'); } //UTF-8 conversions dbexec('ALTER DATABASE CHARACTER SET utf8'); dbexec('ALTER TABLE #__edges CHARACTER SET utf8'); dbexec('ALTER TABLE #__nodes CHARACTER SET utf8'); dbexec('ALTER TABLE #__nodes CHANGE name name VARBINARY(255)'); dbexec('ALTER TABLE #__nodes CHANGE name name VARCHAR(255) CHARACTER SET utf8'); dbexec('ALTER TABLE #__nodes CHANGE alias alias VARBINARY(255)'); dbexec('ALTER TABLE #__nodes CHANGE alias alias VARCHAR(255) CHARACTER SET utf8'); dbexec('ALTER TABLE #__nodes CHANGE body body MEDIUMBLOB'); dbexec('ALTER TABLE #__nodes CHANGE body body MEDIUMTEXT CHARACTER SET utf8'); dbexec('ALTER TABLE #__nodes CHANGE person_given_name person_given_name VARBINARY(255)'); dbexec('ALTER TABLE #__nodes CHANGE person_given_name person_given_name VARCHAR(255) CHARACTER SET utf8'); dbexec('ALTER TABLE #__nodes CHANGE person_family_name person_family_name VARBINARY(255)'); dbexec('ALTER TABLE #__nodes CHANGE person_family_name person_family_name VARCHAR(255) CHARACTER SET utf8'); dbexec('ALTER TABLE #__migrator_migrations CHARACTER SET utf8'); dbexec('ALTER TABLE #__migrator_versions CHARACTER SET utf8'); dbexec('ALTER TABLE #__opensocial_profiles CHARACTER SET utf8'); dbexec('ALTER TABLE #__opensocial_profiles CHARACTER SET utf8'); //move these to related components dbexec('ALTER TABLE #__invites_tokens CHARACTER SET utf8'); dbexec('ALTER TABLE #__opensocial_profiles CHARACTER SET utf8'); dbexec('ALTER TABLE #__subscriptions_coupons CHARACTER SET utf8'); dbexec('ALTER TABLE #__subscriptions_packages CHARACTER SET utf8'); dbexec('ALTER TABLE #__subscriptions_transactions CHARACTER SET utf8'); dbexec('ALTER TABLE #__subscriptions_vats CHARACTER SET utf8'); dbexec('ALTER TABLE #__todos_todos CHARACTER SET utf8'); dbexec('ALTER TABLE #__topics_topics CHARACTER SET utf8'); dbexec('ALTER TABLE #__users CHARACTER SET utf8'); dbexec('ALTER TABLE #__users CHANGE name name VARBINARY(255)'); dbexec('ALTER TABLE #__users CHANGE name name VARCHAR(255) CHARACTER SET utf8'); //updating comments $timeThen = microtime(true); $db = KService::get('koowa:database.adapter.mysqli'); //change comment formats from html to string $entities = dbfetch('SELECT id, body FROM #__nodes WHERE type LIKE "ComBaseDomainEntityComment%" '); dboutput("Updating comments. This WILL take a while ...\n"); foreach ($entities as $entity) { $id = $entity['id']; $body = strip_tags($entity['body']); $db->update('nodes', array('body' => $body), ' WHERE id=' . $id); } dboutput("Comments updated!\n"); $timeDiff = microtime(true) - $timeThen; dboutput("TIME: ({$timeDiff})" . "\n"); }
/** * Called when migrating up. */ public function up() { $timeThen = microtime(true); //remove anahita from nodes and edges table names dbexec('RENAME TABLE #__anahita_nodes TO #__nodes'); dbexec('RENAME TABLE #__anahita_edges TO #__edges'); if (!dbexists('SHOW COLUMNS FROM `#__nodes` LIKE "verified"')) { dbexec("ALTER TABLE `#__nodes` ADD `verified` TINYINT(1) NOT NULL DEFAULT 0 AFTER `enabled`"); } dbexec('ALTER TABLE #__nodes ADD `cover_filename` VARCHAR(255) NULL AFTER `filesize`, ADD `cover_filesize` INT(11) NULL AFTER `cover_filename`, ADD `cover_mimetype` VARCHAR(100) NULL AFTER `cover_filesize`'); dbexec('ALTER TABLE #__nodes ADD `pinned` TINYINT(1) NOT NULL DEFAULT \'0\' AFTER `enabled`'); //some legacy cleanup $legacyTables = array('categories', 'content', 'content_frontpage', 'core_log_items', 'migration_backlinks', 'migrations', 'sections', 'stats_agents', 'tagmeta', 'core_log_searches', 'anahita_oauths'); foreach ($legacyTables as $legacyTable) { dbexec('DROP TABLE IF EXISTS #__' . $legacyTable); } //delete a legacy record dbexec('DELETE FROM #__components WHERE `option` = \'com_mailto\' '); //add the hashtag contentfilter dbexec('INSERT INTO #__plugins (name,element,folder,iscore) VALUES (\'Hashtag\', \'hashtag\',\'contentfilter\',1)'); //create the fields required for creating hashtag nodes dbexec('ALTER TABLE #__nodes DROP COLUMN `tag_count`'); dbexec('ALTER TABLE #__nodes DROP COLUMN `tag_ids`'); //install the hashtag related extensions dbexec('INSERT INTO #__components (`name`,`link`,`option`,`iscore`,`enabled`) VALUES (\'Hashtags\',\'option=com_hashtags\',\'com_hashtags\',1,1)'); $ids = array(); //fetch only the nodes that contain something that resembels a hashtag $query_regexp = 'body REGEXP \'#([^0-9_\\s\\W].{2,})\''; dboutput("\nActors' Hashtags\n"); //extracting hashtag terms from actors $ids = dbfetch('SELECT id FROM #__nodes WHERE type LIKE \'ComActorsDomainEntityActor%\' AND ' . $query_regexp); foreach ($ids as $id) { $entity = KService::get('com://site/actors.domain.entity.actor')->getRepository()->getQuery()->disableChain()->fetch($id); $hashtagTerms = $this->extractHashtagTerms($entity->description); foreach ($hashtagTerms as $term) { dboutput($term . ', '); $entity->addHashtag($term)->save(); } } dboutput("\nComments' hashtags\n"); //extracting hashtag terms from comments $ids = dbfetch('SELECT id FROM #__nodes WHERE type LIKE \'ComBaseDomainEntityComment%\' AND ' . $query_regexp); foreach ($ids as $id) { $entity = KService::get('com://site/base.domain.entity.comment')->getRepository()->getQuery()->disableChain()->fetch($id); $hashtagTerms = $this->extractHashtagTerms($entity->body); foreach ($hashtagTerms as $term) { dboutput($term . ', '); $entity->addHashtag($term)->save(); } } dboutput("\nMedia's Hashtags\n"); //extracting hashtag terms from mediums: notes, topics, articles, and todos $query = 'SELECT id FROM #__nodes WHERE ' . $query_regexp . ' AND ( ' . 'type LIKE \'%com:notes.domain.entity.note\' ' . 'OR type LIKE \'%com:topics.domain.entity.topic\' ' . 'OR type LIKE \'%com:photos.domain.entity.photo\' ' . 'OR type LIKE \'%com:photos.domain.entity.set\' ' . 'OR type LIKE \'%com:articles.domain.entity.article\' ' . 'OR type LIKE \'%com:todos.domain.entity.todo\' ' . ' ) '; $ids = dbfetch($query); foreach ($ids as $id) { $entity = KService::get("repos://site/medium.medium")->getQuery()->disableChain()->find(array('id' => $id)); $hashtagTerms = $this->extractHashtagTerms($entity->description); foreach ($hashtagTerms as $term) { dboutput($term . ', '); $entity->addHashtag($term)->save(); } } dbexec('UPDATE #__plugins SET published = 1 WHERE element = \'hashtag\''); $timeDiff = microtime(true) - $timeThen; dboutput("TIME: ({$timeDiff})" . "\n"); }
/** * Check if a table exists * * @param string $table * * @return boolean */ function dbtable_exists($table) { $table = '#__' . $table; return dbexists("SHOW TABLES LIKE '{$table}'"); }
/** * Called when migrating up */ public function up() { if (!dbexists('SHOW COLUMNS FROM `#__nodes` LIKE "verified"')) { dbexec("ALTER TABLE `#__nodes` ADD `verified` TINYINT(1) NOT NULL DEFAULT 0 AFTER `enabled`"); } }