bool PortalsSystem::_initPortal(const shared_ptr<Portal> &portal, const String &path, bool recovery, bool start) { shared_ptr<PortalOptions> options(OS_NEW PortalOptions()); // Carica le impostazioni del portale if(options->readFromPath(path) == false) return false; if(options->getDeleted()) { deletePortal(options, path); return false; // Portale rimosso } if(portal->load(path, options, recovery) == false) return false; portal->setCachesSize(getCacheSize()); if(start) portal->start(); portal->save(); return true; }
shared_ptr<Portal> PortalsSystem::ensurePortal(shared_ptr<OsirisLink> link, const String &password) { if(link == nullptr) { OS_ASSERTFALSE(); return nullptr; } OS_LOCK(m_cs); shared_ptr<Portal> portal = getPortal(link->getPortal(), link->getPov()); if(portal != nullptr) return portal; shared_ptr<IDbDriver> defaultDriver = DatabasesSystem::instance()->getDefaultDriver(); if(defaultDriver == nullptr) { OS_LOG_ERROR("Invalid database driver"); return nullptr; } PortalID portalID = link->getPortal(); PovID povID = link->getPov(); String portalName = link->getName(); if(portalName.empty()) portalName = portalID.toUTF16(); //String portalDescription = link->getDescription(); shared_ptr<PortalOptions> portalOptions(OS_NEW PortalOptions()); portalOptions->setName(portalName); //portalOptions->setDescription(portalDescription); portalOptions->setPortalID(portalID); portalOptions->setPovID(povID); portalOptions->setPassword(password); portalOptions->setDatabaseDriver(defaultDriver->getName()); portalOptions->setDatabaseOptions(defaultDriver->createOptions()); // VERYURGENT: le varie createPortal/subscribePortal dovrebbero restituire il riferimento al portale portal = subscribePortal(portalOptions); if(portal == nullptr) { OS_LOG_ERROR("Cannot create portal"); return nullptr; } //portal = getPortal(portalID, povID); //OS_ASSERT(portal != nullptr); return portal; }
bool CompatibilityManager::razorUpgrade(const String &folder) { try { if(FileSystem::instance()->directoryExists(folder)) { StringList portals; FileSystem::instance()->getDirectories(folder, portals, false); for(StringList::const_iterator i = portals.begin(); i != portals.end(); ++i) { // 000000018F94C9554C8B227CF000C6E30EB281AEAE1A77E7 String name = *i; if(name.length() == 48) { // Portal < Razor std::string oldID = name.to_ascii(); // Options String oldPath = utils::standardisePath(folder + oldID); shared_ptr<PortalOptions> options(OS_NEW PortalOptions()); // Carica le impostazioni del portale if(options->readFromPath(oldPath) == false) return false; shared_ptr<IDbDriver> driver = DatabasesSystem::instance()->getDriver("sqlite"); // Query Database shared_ptr<IDbConnection> connection = driver->createConnection(oldID, driver->createOptions()); connection->open(); String portalName = options->getName(); //String portalDescription = static_cast<String>(options->getOptionValue("description")); NotificationsManager::instance()->notify(_S("Migration of '") + portalName + _S("' to 1.0 series")); PlatformManager::instance()->sleep(500); //ObjectID userID = static_cast<String>(m_portalOptions.getOption(options::users_reference)).to_ascii(); ObjectID userID = static_cast<String>(options->getOptionValue("users.reference")).to_ascii(); //bool monarchic = (options->getPortalID().getPortalType() == portalTypeMonarchic); ID oldPortalID(oldID); uint8 portalType = OS_UINT8_LO(oldPortalID.getHeader().getFirst()); bool monarchic = (portalType == 1); // Calcolo UserID. // Se non lo posso dedurre, uso il primo che trovo loggato. if(userID.empty()) { if(monarchic) { //userID = options->getPortalID().getAdministratorID(); #ifdef OS_NOOBJECTID userID = oldPortalID.getHash(); #else userID = ObjectID::generate(portalObjectTypeUser, oldPortalID.getHash()); #endif } else { String sql = String::EMPTY; sql += _S(" select tp.profile, tu.reference "); sql += _S(" from "); sql += _S(" os_snapshot_profiles tp, "); sql += _S(" os_snapshot_users tu "); sql += _S(" where "); sql += _S(" tp.profile=tu.profile and "); sql += _S(" tu.score=1 and "); sql += _S(" tu.follow=1 and "); sql += _S(" tu.description='Auto valutation'"); shared_ptr<IDbResult> result = connection->query(sql); DataTable table; result->init(table); DataTableRow row = table.addRow(); while(result->end() == false) { result->bind(row); String objectID = static_cast<String>(*row[1]); userID = objectID.to_ascii(); result->moveNext(); break; } } } #ifdef OS_NOOBJECTID PovID povID = userID; #else PovID povID = userID.getHash(); #endif if(userID.empty() == false) { // Clean old snapshot connection->execute(_S("delete from os_snapshot_objects")); connection->execute(_S("delete from os_snapshot_users")); connection->execute(_S("delete from os_snapshot_profiles")); connection->execute(_S("delete from os_discussions_stats")); //connection->execute(_S("delete from os_forums_forum_stats")); //connection->execute(_S("delete from os_forums_section_stats")); connection->execute(_S("delete from os_polls_stats")); connection->execute(_S("delete from os_polls_options_stats")); connection->execute(_S("delete from os_users_stats")); // Old connection->execute(_S("drop table if exists os_forums_forum_stats")); connection->execute(_S("drop table if exists os_forums_section_stats")); // Reset acceptable connection->execute(_S("update os_entries set rank=-2")); // Clean signatures #ifdef OS_NEWSIGNATURE connection->execute(_S("update os_attributes set signature=x'00'")); connection->execute(_S("update os_avatars set signature=x'00'")); connection->execute(_S("update os_calendar_events set signature=x'00'")); connection->execute(_S("update os_files set signature=x'00'")); connection->execute(_S("update os_instances set signature=x'00'")); connection->execute(_S("update os_models set signature=x'00'")); connection->execute(_S("update os_polls set signature=x'00'")); connection->execute(_S("update os_polls_options set signature=x'00'")); connection->execute(_S("update os_polls_votes set signature=x'00'")); connection->execute(_S("update os_posts set signature=x'00'")); connection->execute(_S("update os_private_messages set signature=x'00'")); connection->execute(_S("update os_reputations set signature=x'00'")); connection->execute(_S("update os_sections set signature=x'00'")); connection->execute(_S("update os_tags set signature=x'00'")); connection->execute(_S("update os_texts set signature=x'00'")); connection->execute(_S("update os_users set signature=x'00'")); connection->execute(_S("update os_votes set signature=x'00'")); #endif // identificarli: // select * from os_users where signature=x'00' } connection->close(); if(userID.empty() == false) { String newPortalIDKey = oldID.substr(8); PortalID newPortalID = CryptManager:: instance()->SHA(newPortalIDKey.buffer(), newPortalIDKey.buffer_size()).toHex(); String newPovID = Portal::generatePovID(newPortalID, povID); String newPath = utils::standardisePath(folder + newPovID); options->setPortalID(newPortalID); options->setPovID(povID); options->setDatabaseName(newPovID); FileSystem::instance()->ensureDirectory(newPath); options->writeToPath(newPath); String sqlitePluginID = _S("532E9E0A68EB22E08240965CFA9366DFA6A26A62"); String databaseRootPath = utils::makeFolderPath(Options::instance()->getDataPath(), utils::makeFolderPath(OS_STORE_PATH, sqlitePluginID)); String oldDatabasePath = utils::makeFilePath(databaseRootPath,oldID) + _S(".db"); String newDatabasePath = utils::makeFilePath(databaseRootPath,newPovID) + _S(".db"); FileSystem::instance()->copyFile(oldDatabasePath, newDatabasePath); FileSystem::instance()->remove(oldDatabasePath); FileSystem::instance()->removeDirectory(oldPath); } else { OS_LOG_ERROR("Unable to migrate portal '" + portalName + "', ID:" + oldID + ". Contact our forum, thanks."); } } } } } catch(std::exception &e) { OS_LOG_ERROR(e.what()); return false; } catch(...) { OS_LOG_ERROR(_S("Unknown error during Razor upgrade.'")); return false; } return true; }
void Subscribe::onSubscribe() { if(m_driver == nullptr) { reportError(httpStatusServiceUnavailable); return; } PortalID portalID = m_portalID->getValue().to_ascii(); String portalName = m_portalName->getValue(); PovID portalPov = m_portalPov->getValue().to_ascii(); if(m_showPortalParams->getCheck() == false) { OsirisLink link; if(link.parse(m_portalLink->getValue().to_ascii()) == false || (link.getType() != OsirisLink::linkPortal)) { showError(getText("main.pages.subscribe.error.invalidPortalLink")); return; } portalID = link.getPortal(); portalName = link.getName(); portalPov = link.getPov(); } shared_ptr<Portal> currentPortal = PortalsSystem::instance()->getPortal(portalID, portalPov); if(currentPortal != nullptr) { redirect(currentPortal->getLink("view")); return; } if(m_driverOptions != nullptr) { const ordered_map<String, String> &driverParams = m_driverOptions->getParams(); for(ordered_map<String, String>::const_iterator i = driverParams.begin(); i != driverParams.end(); ++i) { shared_ptr<IHtmlInput> optionControl = getDriverOptionControl(m_driver->getName(), i->first); if(optionControl != nullptr) { const String ¶mValue = optionControl->getValue(); if(paramValue.empty() == false) m_driverOptions->setParam(i->first, paramValue); } } } shared_ptr<PortalOptions> options(OS_NEW PortalOptions()); options->setPortalID(portalID); options->setPovID(portalPov); options->setName(portalName); options->setPassword(m_portalPassword->getValue()); OS_ASSERT(m_driver->getName() == m_databaseDriver->getValue()); options->setDatabaseDriver(m_driver->getName()); options->setDatabaseOptions(m_driverOptions); shared_ptr<Portal> portal = PortalsSystem::instance()->subscribePortal(options); if(portal != nullptr) //redirect(PortalsSystem::instance()->getAccountsLink(PortalsSystem::instance()->getPortal(portalID, portalUser))); redirect(PortalsSystem::instance()->getPortalLink(portal, "view")); else showError(getText("main.pages.subscribe.error.cannotCreate")); }