void CmpProjectileWeaponUsable::use()
{
	if(m_timeTillCanFire == 0)
	{
		// Determine the character which is firing the projectile (the owner of the weapon).
		ICmpOwnable_CPtr cmpOwnable = m_objectManager->get_component(m_objectID, cmpOwnable);
		ObjectID firer = cmpOwnable->owner();
		if(!firer.valid()) throw Exception("Can't use a projectile weapon when it's not owned");

		// Check that there's enough ammo.
		ICmpInventory_Ptr cmpFirerInventory = m_objectManager->get_component(firer, cmpFirerInventory);
		if(!cmpFirerInventory) throw Exception("The firer must have an inventory component");
		if(cmpFirerInventory->consumables_count(m_ammoType) > 0)
		{
			// Fire a bullet from each hotspot of the weapon (note that this in principle makes it easy to implement things like double-barrelled shotguns).
			const std::vector<std::string>& spots = hotspots();
			for(size_t i=0, size=spots.size(); i<size; ++i)
			{
				boost::optional<Vector3d> pos = hotspot_position(spots[i]);
				boost::optional<Vector3d> ori = hotspot_orientation(spots[i]);
				if(pos && ori)
				{
					ObjectSpecification specification = m_objectManager->get_archetype(m_ammoType);
					specification.set_component_property("Projectile", "Firer", firer);
					specification.set_component_property("Simulation", "Position", *pos);
					specification.set_component_property("Simulation", "Velocity", m_muzzleSpeed * *ori);
					m_objectManager->queue_for_construction(specification);
				}
			}

			cmpFirerInventory->destroy_consumables(m_ammoType, 1);
			m_timeTillCanFire = m_firingInterval;
		}
	}
}
Esempio n. 2
0
//#################### PUBLIC METHODS ####################
void CmdUseActiveItem::execute(const ObjectManager_Ptr& objectManager, const std::vector<CollisionPolygon_Ptr>& polygons, const OnionTree_CPtr& tree,
							   const NavManager_CPtr& navManager, int milliseconds)
{
	ICmpInventory_Ptr cmpInventory = objectManager->get_component(m_objectID, cmpInventory);	if(!cmpInventory) return;
	ObjectID activeItem = cmpInventory->active_item();											if(!activeItem.valid()) return;
	ICmpUsable_Ptr cmpItemUsable = objectManager->get_component(activeItem, cmpItemUsable);		if(!cmpItemUsable) return;
	cmpItemUsable->use();
}
Esempio n. 3
0
int Database::remove(const DatabaseKey &key)
{
    ObjectID oid = mainIndex->get(key);
    if (! oid.isNull()) {
        mainIndex->deleteKey(key);
        slabs->removeData(oid);
    }
    return 0;
}
Esempio n. 4
0
Handle<Value>
ObjectID::ToString(const Arguments &args) {
    ObjectID *o = ObjectWrap::Unwrap<ObjectID>(args.This());

    HandleScope scope;
    char hex[25];
    o->str(hex);
    return String::New(hex);
}
Esempio n. 5
0
Value Database::read(const DatabaseKey &key)
{
    ObjectID oid = mainIndex->get(key);

    if (oid.isNull())
        return nullValue;

    char *result = NULL;
    size_t resultSize = slabs->readData(result, oid);

    return Value(result, resultSize);
}
void CmpCharacterModelRender::render_first_person() const
{
	ICmpInventory_Ptr cmpInventory = m_objectManager->get_component(m_objectID, cmpInventory);
	assert(cmpInventory);

	ObjectID activeItem = cmpInventory->active_item();
	if(!activeItem.valid()) return;

	ICmpBasicModelRender_Ptr cmpItemRender = m_objectManager->get_component(activeItem, cmpItemRender);
	if(!cmpItemRender) return;

	cmpItemRender->render_first_person();
	render_crosshair();
}
void CostAdaptiveStateManager::saveState(const VTime& currentTime, SimulationObject *object) {
   ObjectID *currentObjectID = object->getObjectID();
   unsigned int simObjectID = currentObjectID->getSimulationObjectID(); 

   // The period is only recalculated after the specified number of events.
   if (forwardExecutionLength[simObjectID] < eventsBetweenRecalculation[simObjectID]) {
      forwardExecutionLength[simObjectID]++;
   }
   else{
      calculatePeriod( object );
   }

   AdaptiveStateManagerBase::saveState(currentTime, object);
}
Esempio n. 8
0
void
encodeObjectID(bson_buffer *bb, const char *name, const Local<Value> element) {
    // get at the delicious wrapped object centre
    Local<Object> obj = element->ToObject();
    assert(!obj.IsEmpty());
    assert(obj->InternalFieldCount() > 0);
    ObjectID *o = static_cast<ObjectID*>(Handle<External>::Cast(
                obj->GetInternalField(0))->Value());
    bson_oid_t oid;
    char oid_hex[25];
    o->str(oid_hex);
    bson_oid_from_string(&oid, oid_hex);
    bson_append_oid(bb, name, &oid);
}
Esempio n. 9
0
void IdeMailBox::onRestoreMessage(IEvent *e)
{
	HtmlEvent *htmlEvent = dynamic_cast<HtmlEvent *>(e);
	if(htmlEvent == nullptr)
		return;

	ObjectID id = htmlEvent->get(0).to_ascii();
	if(id.empty() == false)
	{
		// Elimina il messaggio
		getPortal()->getMessenger()->moveMessageToInbox(getPage()->getDatabase(), getSessionAccount(), id);
		// Mostra la posta in arrivo
		_renderFolder(messageFolderInbox);
	}
}
Esempio n. 10
0
void IdeMailBox::onDeleteMessage(IEvent *e)
{
	HtmlEvent *htmlEvent = dynamic_cast<HtmlEvent *>(e);
	if(htmlEvent == nullptr)
		return;

	ObjectID id = htmlEvent->get(0).to_ascii();
	if(id.empty() == false)
	{
		// Elimina il messaggio
		getPortal()->getMessenger()->moveMessageToTrash(getPage()->getDatabase(), getSessionAccount(), id);
		// Mostra la directory di riferimento
		_renderFolder(m_folder);
	}
}
 void ComponentManager::deregisterContainer(const ObjectID& oid) {
     unsigned int index = oid.getIndex();
     m_activeContainers.erase(index);
     m_containers[index] = 0;
     std::memset(&m_componentIDs[index * MAX_INTERFACES], 0, sizeof (ComponentID) * MAX_INTERFACES);
     m_containerIndices.free(index);
     //std::cout << "Object " << oid.getIndex() << " deregistered." << std::endl;
 }
Esempio n. 12
0
Handle<Value> ObjectID::New(const Arguments &args) {
    HandleScope scope;

    if (args.Length() < 1
           || !args[0]->IsString()
           || (args[0]->IsString()
                && args[0]->ToString()->Length() != 24)) {
        return ThrowException(Exception::Error(
                String::New("Argument must be 24 character hex string")));
    }

    String::Utf8Value hex(args[0]->ToString());

    // XXX where should this be deleted?
    ObjectID *o = new ObjectID((const char *) *hex);
    o->Wrap(args.This());
    return args.This();
}
void CmpCharacterModelRender::render() const
{
	ICmpOrientation_CPtr cmpOrientation = m_objectManager->get_component(m_objectID, cmpOrientation);
	ICmpPosition_CPtr cmpPosition = m_objectManager->get_component(m_objectID, cmpPosition);

	const Vector3d& p = cmpPosition->position();
	const Vector3d& n = cmpOrientation->nuv_axes()->n();
	const Vector3d& u = cmpOrientation->nuv_axes()->u();
	const Vector3d& v = cmpOrientation->nuv_axes()->v();

	if(m_modelPose != NULL)
	{
		RBTMatrix_CPtr mat = construct_model_matrix(p, n, u, v);
		glPushMatrix();
			glMultMatrixd(&mat->rep()[0]);

			// Render the model.
			model()->render(m_modelPose);

			// Render the active item (if any).
			ICmpInventory_Ptr cmpInventory = m_objectManager->get_component(m_objectID, cmpInventory);	assert(cmpInventory);
			ObjectID activeItem = cmpInventory->active_item();
			if(activeItem.valid())
			{
				ICmpBasicModelRender_Ptr cmpItemRender = m_objectManager->get_component(activeItem, cmpItemRender);
				if(cmpItemRender)
				{
					cmpItemRender->render_child();
				}
			}
		glPopMatrix();
	}

	if(m_highlights)
	{
		// If the object should be highlighted, render the object's bounds.
		render_bounds(p);
	}

	// Render the object's NUV axes.
	render_nuv_axes(p, n, u, v);
}
Esempio n. 14
0
void ObjectManager::post_message(const ObjectID& target, const Message_CPtr& msg)
{
	std::map<ObjectID,Object>::iterator it = m_objects.find(target);
	if(it == m_objects.end()) throw Exception("Invalid object ID: " + target.to_string());

	Object& obj = it->second;
	for(Object::iterator jt=obj.begin(), jend=obj.end(); jt!=jend; ++jt)
	{
		msg->dispatch(jt->second.get());
	}
}
void ThreadedCostAdaptiveStateManager::saveState(const VTime& currentTime,
		SimulationObject *object, int threadID) {
	ObjectID *currentObjectID = object->getObjectID();
	unsigned int simObjectID = currentObjectID->getSimulationObjectID();

	// The period is only recalculated after the specified number of events.
	if (forwardExecutionLength[simObjectID]
			< eventsBetweenRecalculation[simObjectID]) {
		forwardExecutionLength[simObjectID]++;
	} else {
		calculatePeriod(object);
	}
	if (periodCounter[simObjectID] <= 1) {
		// we need to first allocate a state. Copy the current state into
		// this newly created state. Then allocate a state object and
		// fill in the current time and a pointer to the newly copied
		// current state.
		startStateTiming(simObjectID);

		State *newState = object->allocateState();
		newState->copyState(object->getState());
		SetObject<State> stateObject(currentTime, newState);

		// look up the state queue of the simulation object and insert the
		// newly allocated state object
		ThreadedStateManagerImplementationBase::getStateQueueLock(threadID,
				simObjectID);
		myStateQueue[simObjectID].insert(stateObject);
		/*cout << "Saving at the Time Stamp :::::"
		 << currentTime.getApproximateIntTime() << endl;*/
		ThreadedStateManagerImplementationBase::releaseStateQueueLock(threadID,
				simObjectID);

		// reset period counter to state period
		periodCounter[simObjectID] = objectStatePeriod[simObjectID];
		stopStateTiming(simObjectID);
	} else {
		// decrement period counter
		periodCounter[simObjectID] = periodCounter[simObjectID] - 1;
	}
}
Esempio n. 16
0
//#################### CONSTRUCTORS ####################
CmpInventory::CmpInventory(const ObjectID& activeItem, const std::map<std::string,int>& consumables, const std::set<ObjectID>& items)
:	m_initialised(false), m_activeItem(activeItem), m_consumables(consumables), m_items(items)
{
	// Note:	We can't update the usable groups at this stage, because the items we're holding generally haven't been created yet.
	//			Instead, they are initialised "on demand" later on.

	// Check that the active item (if any) is actually one of the items in the inventory.
	if(activeItem.valid() && items.find(activeItem) == items.end())
	{
		throw Exception("The active item must be in the inventory");
	}
}
Esempio n. 17
0
void ObjectManager::destroy_object(const ObjectID& id)
{
	// Remove all the listeners which are components of the object being deleted.
	m_listenerTable.remove_listeners_from(id);

	broadcast_message(Message_CPtr(new MsgObjectDestroyed(id)));

	// Remove all the listeners referring to the object.
	m_listenerTable.remove_listeners_to(id);

	m_objects.erase(id);
	m_idAllocator.deallocate(id.value());
}
Esempio n. 18
0
std::vector<IObjectComponent_Ptr> ObjectManager::get_components(const ObjectID& id)
{
	std::map<ObjectID,Object>::iterator it = m_objects.find(id);
	if(it == m_objects.end()) throw Exception("Invalid object ID: " + id.to_string());

	Object& object = it->second;

	std::vector<IObjectComponent_Ptr> components;
	for(Object::const_iterator jt=object.begin(), jend=object.end(); jt!=jend; ++jt)
	{
		components.push_back(jt->second);
	}
	return components;
}
void CBRLocationServiceCache::addPlaceholderImposter(
    const ObjectID& uuid,
    const Vector3f& center_offset,
    const float32 center_bounds_radius,
    const float32 max_size,
    const String& zernike,
    const String& mesh
) {
    TimedMotionVector3f loc(mLoc->context()->simTime(), MotionVector3f(center_offset, Vector3f(0,0,0)));
    TimedMotionQuaternion orient;
    AggregateBoundingInfo bounds(Vector3f(0, 0, 0), center_bounds_radius, max_size);
    String phy;
    objectAdded(
        uuid.getAsUUID(), true, true, loc, orient, bounds, mesh, phy, zernike
    );
}
 MessageResult ComponentManager::sendMessage(const InterfaceTypeID& iid, const ObjectID& oid, MessageBase& msg) {
     const ComponentID& cid = getComponentID(iid, oid);
     if (cid.isValid()) {
         ComponentBase* component = getComponent(cid);
         if (component) {
             // write on envelope
             // this changes msg!
             msg.Addressee = oid;
             msg.Sender = ObjectID();
             return component->handleMessage(msg);
         }
         std::cerr << "Component invalid in container " << oid.getIndex() << std::endl;
         return MR_ERROR; // failed to deliver
     }
     return MR_ERROR; // failed to deliver
 }
void ThreadedCostAdaptiveStateManager::updateStateWhileCoastForward(
		const VTime& currentTime, unsigned int eventNumber,
		SimulationObject *object, const ObjectID senderId, int threadID) {
	// store this object's id temporarily
	OBJECT_ID *currentObjectID = object->getObjectID();
	unsigned int simObjectID = currentObjectID->getSimulationObjectID();
	if (mySimulationManager->isRollbackJustCompleted(simObjectID)) {
		/*cout << "Last Rollback Time ::{{{{{{{{{{{{{{{{{}}}}}}}} "
		 << *(lastRollbackTime[simObjectID]) << endl;*/
		multiset<SetObject<State> >::iterator iter_end =
				myStateQueue[simObjectID].end();
		/*cout << "Current Num = " << eventNumber << ":::::  Old Number = "
		 << rollbackEventNumber[simObjectID] << endl;*/
		if (*(lastRollbackTime[simObjectID]) == currentTime && eventNumber
				<= rollbackEventNumber[simObjectID]) {
			/*cout << " Need to update the Event Number in the state ::::"
			 << eventNumber << endl;*/
			ThreadedStateManagerImplementationBase::getStateQueueLock(threadID,
					simObjectID);
			State *newState = object->allocateState();
			newState->copyState(object->getState());
			SetObject<State> stateObject(currentTime, newState, eventNumber,
					senderId.getSimulationObjectID(),
					senderId.getSimulationObjectID());
			//object->deallocateState((*iter_end).getElement());
			//myStateQueue[simObjectID].erase(iter_end);
			// look up the state queue of the simulation object and insert the
			// newly allocated state object

			myStateQueue[simObjectID].insert(stateObject);
			ThreadedStateManagerImplementationBase::releaseStateQueueLock(
					threadID, simObjectID);
		}
		mySimulationManager->resetRollbackCompletedStatus(simObjectID);
	}
}
void CmpCharacterModelRender::update_animation(int milliseconds)
{
	// Decide which animation should be playing, and update it.
	ICmpAnimChooser_Ptr cmpAnimChooser = m_objectManager->get_component(m_objectID, cmpAnimChooser);	assert(cmpAnimChooser);
	m_animController->request_animation(cmpAnimChooser->choose_animation());
	m_animController->update(milliseconds);

	// Clear any existing pose modifiers.
	m_animController->clear_pose_modifiers();

	// Determine the animation extension of any carried item in order to determine which bones need to be inclined.
	std::string animExtension = "";		// the explicit initialisation is to make it clear that "" is the default

	ICmpInventory_Ptr cmpInventory = m_objectManager->get_component(m_objectID, cmpInventory);	assert(cmpInventory);
	ObjectID activeItem = cmpInventory->active_item();
	if(activeItem.valid())
	{
		ICmpOwnable_Ptr cmpItemOwnable = m_objectManager->get_component(activeItem, cmpItemOwnable);	assert(cmpItemOwnable);
		animExtension = cmpItemOwnable->anim_extension();
	}

	// Calculate the inclination of the object's coordinate system and apply pose modifiers to the relevant bones.
	BoneModifierMap::const_iterator it = m_inclineBones.find(animExtension);
	if(it != m_inclineBones.end())
	{
		ICmpOrientation_Ptr cmpOrientation = m_objectManager->get_component(m_objectID, cmpOrientation);
		const Vector3d& n = cmpOrientation->nuv_axes()->n();

		double sinInclination = n.z / n.length();
		if(sinInclination < -1) sinInclination = -1;
		if(sinInclination > 1) sinInclination = 1;
		double inclination = asin(sinInclination);

		for(std::map<std::string,Vector3d>::const_iterator jt=it->second.begin(), jend=it->second.end(); jt!=jend; ++jt)
		{
			m_animController->set_pose_modifier(jt->first, PoseModifier(jt->second, -inclination));
		}
	}

	// Configure the pose.
	m_modelPose = model()->configure_pose(m_animController);

	// Update the animation for the active item (if any), e.g. the weapon being carried.
	if(activeItem.valid())
	{
		ICmpOrientation_CPtr cmpOrientation = m_objectManager->get_component(m_objectID, cmpOrientation);
		ICmpPosition_CPtr cmpPosition = m_objectManager->get_component(m_objectID, cmpPosition);

		const Vector3d& p = cmpPosition->position();
		const Vector3d& n = cmpOrientation->nuv_axes()->n();
		const Vector3d& u = cmpOrientation->nuv_axes()->u();
		const Vector3d& v = cmpOrientation->nuv_axes()->v();

		RBTMatrix_CPtr modelMatrix = construct_model_matrix(p, n, u, v);

		ICmpOwnable_Ptr cmpItemOwnable = m_objectManager->get_component(activeItem, cmpItemOwnable);	assert(cmpItemOwnable);
		ICmpBasicModelRender_Ptr cmpItemRender = m_objectManager->get_component(activeItem, cmpItemRender);
		if(cmpItemRender)
		{
			cmpItemRender->update_child_animation(milliseconds, skeleton()->bone_hierarchy(), cmpItemOwnable->attach_point(), modelMatrix);
		}
	}
}
Esempio n. 23
0
	uint32 HashValue() const
	{
		return variable->HashValue() ^ path->HashValue();
	}
Esempio n. 24
0
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;
}
Esempio n. 25
0
bool CompatibilityManager::razorPortalDatabaseUpgrade(const shared_ptr<IPortalDatabase> &database)
{
	PovID povID = database->getPortal()->getPovID();
#ifdef OS_NOOBJECTID
	ObjectID userID = povID;
#else
	ObjectID userID = ObjectID::generate(portalObjectTypeUser, povID.getString());
#endif

	migrateAccounts(database);

	
	String portalName = database->getPortal()->getOptions()->getName();
	String portalDescription = static_cast<String>(database->getPortal()->getOptions()->getOptionValue("description"));

	// Clean old snapshot
	database->execute(_S("delete from os_snapshot_objects"));
	database->execute(_S("delete from os_snapshot_users"));
	//database->execute(_S("delete from os_snapshot_profiles"));
	database->execute(_S("delete from os_discussions_stats"));
	//database->execute(_S("delete from os_forums_forum_stats"));
	//database->execute(_S("delete from os_forums_section_stats"));
	database->execute(_S("delete from os_polls_stats"));
	database->execute(_S("delete from os_polls_options_stats"));
	database->execute(_S("delete from os_users_stats"));

	// Old
	database->execute(_S("drop table if exists os_forums_forum_stats"));
	database->execute(_S("drop table if exists os_forums_section_stats"));

	// Reset acceptable
	database->execute(_S("update os_entries set rank=-2"));

	// Clean signatures
	database->execute(_S("update os_attributes set signature=x'00'"));
	database->execute(_S("update os_avatars set signature=x'00'"));
	database->execute(_S("update os_calendar_events set signature=x'00'"));
	database->execute(_S("update os_files set signature=x'00'"));
	database->execute(_S("update os_instances set signature=x'00'"));
	database->execute(_S("update os_models set signature=x'00'"));
	database->execute(_S("update os_polls set signature=x'00'"));
	database->execute(_S("update os_polls_options set signature=x'00'"));
	database->execute(_S("update os_polls_votes set signature=x'00'"));
	database->execute(_S("update os_posts set signature=x'00'"));
	database->execute(_S("update os_private_messages set signature=x'00'"));
	database->execute(_S("update os_reputations set signature=x'00'"));
	database->execute(_S("update os_sections set signature=x'00'"));
	database->execute(_S("update os_tags set signature=x'00'"));
	database->execute(_S("update os_texts set signature=x'00'"));
	database->execute(_S("update os_users set signature=x'00'"));
	database->execute(_S("update os_votes set signature=x'00'"));

	// Other conversions
	database->execute(_S("update os_entries set entity=null where entity='';\r\n"));
	database->execute(_S("update os_calendar_events set entity=null where entity='';\r\n"));
	database->execute(_S("update os_files set entity=null where entity='';\r\n"));
	database->execute(_S("update os_instances set entity=null where entity='';\r\n"));
	database->execute(_S("update os_models set entity=null where entity='';\r\n"));
	database->execute(_S("update os_polls set entity=null where entity='';\r\n"));
	database->execute(_S("update os_polls_options set entity=null where entity='';\r\n"));
	database->execute(_S("update os_posts set entity=null where entity='';\r\n"));
	database->execute(_S("update os_sections set entity=null where entity='';\r\n"));
	database->execute(_S("update os_tags set entity=null where entity='';\r\n"));
	database->execute(_S("update os_texts set entity=null where entity='';\r\n"));
		
	database->execute(_S("update os_attributes set pov='") + povID.toUTF16() + _S("';\r\n"));
	database->execute(_S("update os_avatars set pov='") + povID.toUTF16() + _S("';\r\n"));
	database->execute(_S("update os_calendar_events set pov='") + povID.toUTF16() + _S("';\r\n"));
	database->execute(_S("update os_files set pov='") + povID.toUTF16() + _S("';\r\n"));
	database->execute(_S("update os_instances set pov='") + povID.toUTF16() + _S("';\r\n"));
	database->execute(_S("update os_models set pov='") + povID.toUTF16() + _S("';\r\n"));
	database->execute(_S("update os_polls set pov='") + povID.toUTF16() + _S("';\r\n"));
	database->execute(_S("update os_polls_options set pov='") + povID.toUTF16() + _S("';\r\n"));
	database->execute(_S("update os_polls_votes set pov='") + povID.toUTF16() + _S("';\r\n"));
	database->execute(_S("update os_posts set pov='") + povID.toUTF16() + _S("';\r\n"));
	database->execute(_S("update os_private_messages set pov='") + povID.toUTF16() + _S("';\r\n"));
	database->execute(_S("update os_reputations set pov='") + povID.toUTF16() + _S("';\r\n"));
	database->execute(_S("update os_sections set pov='") + povID.toUTF16() + _S("';\r\n"));
	database->execute(_S("update os_tags set pov='") + povID.toUTF16() + _S("';\r\n"));
	database->execute(_S("update os_texts set pov='") + povID.toUTF16() + _S("';\r\n"));
	database->execute(_S("update os_users set pov='") + povID.toUTF16() + _S("';\r\n"));
	database->execute(_S("update os_votes set pov='") + povID.toUTF16() + _S("';\r\n"));

	database->execute(_S("update os_entries set entity=ifnull(entity,id);\r\n"));

	database->execute(_S("update os_calendar_events set entity=ifnull(entity,id);\r\n"));
	database->execute(_S("update os_files set entity=ifnull(entity,id);\r\n"));
	database->execute(_S("update os_instances set entity=ifnull(entity,id);\r\n"));
	database->execute(_S("update os_models set entity=ifnull(entity,id);\r\n"));
	database->execute(_S("update os_polls set entity=ifnull(entity,id);\r\n"));
	database->execute(_S("update os_polls_options set entity=ifnull(entity,id);\r\n"));
	database->execute(_S("update os_posts set entity=ifnull(entity,id);\r\n"));
	database->execute(_S("update os_sections set entity=ifnull(entity,id);\r\n"));
	database->execute(_S("update os_tags set entity=ifnull(entity,id);\r\n"));
	database->execute(_S("update os_texts set entity=ifnull(entity,id);\r\n"));
				
	database->execute(_S("update os_calendar_events set entity_author=(select author from os_entries where os_entries.id = os_calendar_events.entity);\r\n"));
	database->execute(_S("update os_files set entity_author=(select author from os_entries where os_entries.id = os_files.entity);\r\n"));
	database->execute(_S("update os_instances set entity_author=(select author from os_entries where os_entries.id = os_instances.entity);\r\n"));
	database->execute(_S("update os_models set entity_author=(select author from os_entries where os_entries.id = os_models.entity);\r\n"));
	database->execute(_S("update os_polls set entity_author=(select author from os_entries where os_entries.id = os_polls.entity);\r\n"));
	database->execute(_S("update os_polls_options set entity_author=(select author from os_entries where os_entries.id = os_polls_options.entity);\r\n"));
	database->execute(_S("update os_posts set entity_author=(select author from os_entries where os_entries.id = os_posts.entity);\r\n"));
	database->execute(_S("update os_sections set entity_author=(select author from os_entries where os_entries.id = os_sections.entity);\r\n"));
	database->execute(_S("update os_tags set entity_author=(select author from os_entries where os_entries.id = os_tags.entity);\r\n"));
	database->execute(_S("update os_texts set entity_author=(select author from os_entries where os_entries.id = os_texts.entity);\r\n"));

	database->execute(_S("update os_calendar_events set entity_date=(select submit_date from os_entries where os_entries.id = os_calendar_events.entity);\r\n"));
	database->execute(_S("update os_files set entity_date=(select submit_date from os_entries where os_entries.id = os_files.entity);\r\n"));
	database->execute(_S("update os_instances set entity_date=(select submit_date from os_entries where os_entries.id = os_instances.entity);\r\n"));
	database->execute(_S("update os_models set entity_date=(select submit_date from os_entries where os_entries.id = os_models.entity);\r\n"));
	database->execute(_S("update os_polls set entity_date=(select submit_date from os_entries where os_entries.id = os_polls.entity);\r\n"));
	database->execute(_S("update os_polls_options set entity_date=(select submit_date from os_entries where os_entries.id = os_polls_options.entity);\r\n"));
	database->execute(_S("update os_posts set entity_date=(select submit_date from os_entries where os_entries.id = os_posts.entity);\r\n"));
	database->execute(_S("update os_sections set entity_date=(select submit_date from os_entries where os_entries.id = os_sections.entity);\r\n"));
	database->execute(_S("update os_tags set entity_date=(select submit_date from os_entries where os_entries.id = os_tags.entity);\r\n"));
	database->execute(_S("update os_texts set entity_date=(select submit_date from os_entries where os_entries.id = os_texts.entity);\r\n"));

	database->execute(_S("update os_calendar_events set entity_parent=(select parent from os_entries where os_entries.id = os_calendar_events.entity);\r\n"));
	database->execute(_S("update os_files set entity_parent=(select parent from os_entries where os_entries.id = os_files.entity);\r\n"));
	database->execute(_S("update os_instances set entity_parent=(select parent from os_entries where os_entries.id = os_instances.entity);\r\n"));
	database->execute(_S("update os_models set entity_parent=(select parent from os_entries where os_entries.id = os_models.entity);\r\n"));
	database->execute(_S("update os_polls set entity_parent=(select parent from os_entries where os_entries.id = os_polls.entity);\r\n"));
	database->execute(_S("update os_polls_options set entity_parent=(select parent from os_entries where os_entries.id = os_polls_options.entity);\r\n"));
	database->execute(_S("update os_posts set entity_parent=(select parent from os_entries where os_entries.id = os_posts.entity);\r\n"));
	database->execute(_S("update os_sections set entity_parent=(select parent from os_entries where os_entries.id = os_sections.entity);\r\n"));
	database->execute(_S("update os_tags set entity_parent=(select parent from os_entries where os_entries.id = os_tags.entity);\r\n"));
	database->execute(_S("update os_texts set entity_parent=(select parent from os_entries where os_entries.id = os_texts.entity);\r\n"));

	database->execute(_S("CREATE INDEX os_files_index_entity_temp on os_files (entity asc);\r\n"));
	database->execute(_S("CREATE INDEX os_texts_index_entity_temp on os_texts (entity asc);\r\n"));
	database->execute(_S("CREATE INDEX os_posts_index_entity_temp on os_posts (entity asc);\r\n"));

	database->execute(_S("update os_entries set entity_author=(select entity_author from os_calendar_events where os_entries.entity = os_calendar_events.entity) where type=16;\r\n"));
	database->execute(_S("update os_entries set entity_author=(select entity_author from os_files where os_entries.entity = os_files.entity) where type=8;\r\n"));
	database->execute(_S("update os_entries set entity_author=(select entity_author from os_instances where os_entries.entity = os_instances.entity) where type=4;\r\n"));
	database->execute(_S("update os_entries set entity_author=(select entity_author from os_models where os_entries.entity = os_models.entity) where type=15;\r\n"));
	database->execute(_S("update os_entries set entity_author=(select entity_author from os_polls where os_entries.entity = os_polls.entity) where type=12;\r\n"));
	database->execute(_S("update os_entries set entity_author=(select entity_author from os_polls_options where os_entries.entity = os_polls_options.entity) where type=13;\r\n"));
	database->execute(_S("update os_entries set entity_author=(select entity_author from os_posts where os_entries.entity = os_posts.entity) where type=6;\r\n"));
	database->execute(_S("update os_entries set entity_author=(select entity_author from os_sections where os_entries.entity = os_sections.entity) where type=3;\r\n"));
	database->execute(_S("update os_entries set entity_author=(select entity_author from os_tags where os_entries.entity = os_tags.entity) where type=9;\r\n"));
	database->execute(_S("update os_entries set entity_author=(select entity_author from os_texts where os_entries.entity = os_texts.entity) where type=5;\r\n"));

	database->execute(_S("update os_entries set entity_date=(select entity_date from os_calendar_events where os_entries.entity = os_calendar_events.entity) where type=16;\r\n"));
	database->execute(_S("update os_entries set entity_date=(select entity_date from os_files where os_entries.entity = os_files.entity) where type=8;\r\n"));
	database->execute(_S("update os_entries set entity_date=(select entity_date from os_instances where os_entries.entity = os_instances.entity) where type=4;\r\n"));
	database->execute(_S("update os_entries set entity_date=(select entity_date from os_models where os_entries.entity = os_models.entity) where type=15;\r\n"));
	database->execute(_S("update os_entries set entity_date=(select entity_date from os_polls where os_entries.entity = os_polls.entity) where type=12;\r\n"));
	database->execute(_S("update os_entries set entity_date=(select entity_date from os_polls_options where os_entries.entity = os_polls_options.entity) where type=13;\r\n"));
	database->execute(_S("update os_entries set entity_date=(select entity_date from os_posts where os_entries.entity = os_posts.entity) where type=6;\r\n"));
	database->execute(_S("update os_entries set entity_date=(select entity_date from os_sections where os_entries.entity = os_sections.entity) where type=3;\r\n"));
	database->execute(_S("update os_entries set entity_date=(select entity_date from os_tags where os_entries.entity = os_tags.entity) where type=9;\r\n"));
	database->execute(_S("update os_entries set entity_date=(select entity_date from os_texts where os_entries.entity = os_texts.entity) where type=5;\r\n"));

	database->execute(_S("update os_entries set entity=null,entity_author=null,entity_date=null where type not in (16,8,4,15,12,13,6,3,9,5);\r\n"));

	database->execute(_S("drop index os_files_index_entity_temp;\r\n"));
	database->execute(_S("drop index os_texts_index_entity_temp;\r\n"));
	database->execute(_S("drop index os_posts_index_entity_temp;\r\n"));

	// Object header cleaning - Entity
	database->execute(_S("update os_entries set entity=substr(entity,9);\r\n"));
	database->execute(_S("update os_calendar_events set entity=substr(entity,9);\r\n"));
	database->execute(_S("update os_files set entity=substr(entity,9);\r\n"));
	database->execute(_S("update os_instances set entity=substr(entity,9);\r\n"));
	database->execute(_S("update os_models set entity=substr(entity,9);\r\n"));
	database->execute(_S("update os_polls set entity=substr(entity,9);\r\n"));
	database->execute(_S("update os_polls_options set entity=substr(entity,9);\r\n"));
	database->execute(_S("update os_posts set entity=substr(entity,9);\r\n"));
	database->execute(_S("update os_sections set entity=substr(entity,9);\r\n"));
	database->execute(_S("update os_tags set entity=substr(entity,9);\r\n"));
	database->execute(_S("update os_texts set entity=substr(entity,9);\r\n"));

	database->execute(_S("update os_entries set parent=substr(parent,9);\r\n"));
	database->execute(_S("update os_calendar_events set parent=substr(parent,9);\r\n"));
	database->execute(_S("update os_files set parent=substr(parent,9);\r\n"));
	database->execute(_S("update os_instances set parent=substr(parent,9);\r\n"));
	database->execute(_S("update os_models set parent=substr(parent,9);\r\n"));
	database->execute(_S("update os_polls set parent=substr(parent,9);\r\n"));
	database->execute(_S("update os_polls_options set parent=substr(parent,9);\r\n"));
	database->execute(_S("update os_posts set parent=substr(parent,9);\r\n"));
	database->execute(_S("update os_sections set parent=substr(parent,9);\r\n"));
	database->execute(_S("update os_tags set parent=substr(parent,9);\r\n"));
	database->execute(_S("update os_texts set parent=substr(parent,9);\r\n"));

	database->execute(_S("update os_calendar_events set entity_parent=substr(entity_parent,9);\r\n"));
	database->execute(_S("update os_files set entity_parent=substr(entity_parent,9);\r\n"));
	database->execute(_S("update os_instances set entity_parent=substr(entity_parent,9);\r\n"));
	database->execute(_S("update os_models set entity_parent=substr(entity_parent,9);\r\n"));
	database->execute(_S("update os_polls set entity_parent=substr(entity_parent,9);\r\n"));
	database->execute(_S("update os_polls_options set entity_parent=substr(entity_parent,9);\r\n"));
	database->execute(_S("update os_posts set entity_parent=substr(entity_parent,9);\r\n"));
	database->execute(_S("update os_sections set entity_parent=substr(entity_parent,9);\r\n"));
	database->execute(_S("update os_tags set entity_parent=substr(entity_parent,9);\r\n"));
	database->execute(_S("update os_texts set entity_parent=substr(entity_parent,9);\r\n"));

	// Object header cleaning - ObjectID
	database->execute(_S("update os_entries set id=substr(id,9) where length(id)=48;\r\n"));
	database->execute(_S("update os_entries set author=substr(author,9) where length(author)=48;\r\n"));
	database->execute(_S("update os_entries set entity_author=substr(entity_author,9) where length(entity_author)=48;\r\n"));

	database->execute(_S("update os_attributes set id=substr(id,9) where length(id)=48;\r\n"));
	database->execute(_S("update os_attributes set author=substr(author,9) where length(author)=48;\r\n"));

	database->execute(_S("update os_avatars set id=substr(id,9) where length(id)=48;\r\n"));
	database->execute(_S("update os_avatars set author=substr(author,9) where length(author)=48;\r\n"));

	database->execute(_S("update os_local_messages set id=substr(id,9) where length(id)=48;\r\n"));
	database->execute(_S("update os_local_messages set author=substr(author,9) where length(author)=48;\r\n"));

	database->execute(_S("update os_polls_votes set id=substr(id,9) where length(id)=48;\r\n"));
	database->execute(_S("update os_polls_votes set author=substr(author,9) where length(author)=48;\r\n"));
	database->execute(_S("update os_polls_votes set reference=substr(reference,9) where length(reference)=48;\r\n"));

	database->execute(_S("update os_votes set id=substr(id,9) where length(id)=48;\r\n"));
	database->execute(_S("update os_votes set author=substr(author,9) where length(author)=48;\r\n"));
	database->execute(_S("update os_votes set reference=substr(reference,9) where length(reference)=48;\r\n"));

	database->execute(_S("update os_private_messages set id=substr(id,9) where length(id)=48;\r\n"));
	database->execute(_S("update os_private_messages set author=substr(author,9) where length(author)=48;\r\n"));
	database->execute(_S("update os_private_messages set adressee=substr(adressee,9) where length(adressee)=48;\r\n"));

	database->execute(_S("update os_reputations set id=substr(id,9) where length(id)=48;\r\n"));
	database->execute(_S("update os_reputations set author=substr(author,9) where length(author)=48;\r\n"));
	database->execute(_S("update os_reputations set reference=substr(reference,9) where length(reference)=48;\r\n"));

	database->execute(_S("update os_users set id=substr(id,9) where length(id)=48;\r\n"));

	database->execute(_S("update os_calendar_events set id=substr(id,9) where length(id)=48;\r\n"));
	database->execute(_S("update os_calendar_events set author=substr(author,9) where length(author)=48;\r\n"));
	database->execute(_S("update os_calendar_events set entity_author=substr(entity_author,9) where length(entity_author)=48;\r\n"));
	database->execute(_S("update os_files set id=substr(id,9) where length(id)=48;\r\n"));
	database->execute(_S("update os_files set author=substr(author,9) where length(author)=48;\r\n"));
	database->execute(_S("update os_files set entity_author=substr(entity_author,9) where length(entity_author)=48;\r\n"));
	database->execute(_S("update os_instances set id=substr(id,9) where length(id)=48;\r\n"));
	database->execute(_S("update os_instances set author=substr(author,9) where length(author)=48;\r\n"));
	database->execute(_S("update os_instances set entity_author=substr(entity_author,9) where length(entity_author)=48;\r\n"));
	database->execute(_S("update os_models set id=substr(id,9) where length(id)=48;\r\n"));
	database->execute(_S("update os_models set author=substr(author,9) where length(author)=48;\r\n"));
	database->execute(_S("update os_models set entity_author=substr(entity_author,9) where length(entity_author)=48;\r\n"));
	database->execute(_S("update os_polls set id=substr(id,9) where length(id)=48;\r\n"));
	database->execute(_S("update os_polls set author=substr(author,9) where length(author)=48;\r\n"));
	database->execute(_S("update os_polls set entity_author=substr(entity_author,9) where length(entity_author)=48;\r\n"));
	database->execute(_S("update os_polls_options set id=substr(id,9) where length(id)=48;\r\n"));
	database->execute(_S("update os_polls_options set author=substr(author,9) where length(author)=48;\r\n"));
	database->execute(_S("update os_polls_options set entity_author=substr(entity_author,9) where length(entity_author)=48;\r\n"));
	database->execute(_S("update os_posts set id=substr(id,9) where length(id)=48;\r\n"));
	database->execute(_S("update os_posts set author=substr(author,9) where length(author)=48;\r\n"));
	database->execute(_S("update os_posts set entity_author=substr(entity_author,9) where length(entity_author)=48;\r\n"));
	database->execute(_S("update os_sections set id=substr(id,9) where length(id)=48;\r\n"));
	database->execute(_S("update os_sections set author=substr(author,9) where length(author)=48;\r\n"));
	database->execute(_S("update os_sections set entity_author=substr(entity_author,9) where length(entity_author)=48;\r\n"));
	database->execute(_S("update os_tags set id=substr(id,9) where length(id)=48;\r\n"));
	database->execute(_S("update os_tags set author=substr(author,9) where length(author)=48;\r\n"));
	database->execute(_S("update os_tags set entity_author=substr(entity_author,9) where length(entity_author)=48;\r\n"));
	database->execute(_S("update os_texts set id=substr(id,9) where length(id)=48;\r\n"));
	database->execute(_S("update os_texts set author=substr(author,9) where length(author)=48;\r\n"));
	database->execute(_S("update os_texts set entity_author=substr(entity_author,9) where length(entity_author)=48;\r\n"));
	
	// Special for Osiris Official
	database->execute(_S("update os_entries set author='3CCB3260950B80505CBB062C0B9B65E7028BD53F' where author='EFA5BEDD264F19D35BA92F05E503AD477D432E9F' and type=3;\r\n"));
	database->execute(_S("update os_entries set author='3CCB3260950B80505CBB062C0B9B65E7028BD53F' where author='EFA5BEDD264F19D35BA92F05E503AD477D432E9F' and type=8;\r\n"));
	database->execute(_S("update os_files set author='3CCB3260950B80505CBB062C0B9B65E7028BD53F',entity_author='3CCB3260950B80505CBB062C0B9B65E7028BD53F' where author='EFA5BEDD264F19D35BA92F05E503AD477D432E9F';\r\n"));
	database->execute(_S("update os_sections set author='3CCB3260950B80505CBB062C0B9B65E7028BD53F',entity_author='3CCB3260950B80505CBB062C0B9B65E7028BD53F' where author='EFA5BEDD264F19D35BA92F05E503AD477D432E9F';\r\n"));

	// Cleaning... issue found in some old portals.
	database->execute(_S("delete from os_models where id not in (select id from os_entries);\r\n"));
	database->execute(_S("drop table if exists os_commentables_stats;\r\n"));

	//if(database->execute(patch) == false)
	//	return false;

	// Default POV Options
	{
		String povOptions;
		povOptions += _S("<options>");
		povOptions += _S("<option name=\"acp.objects.allow_unsigned\" value=\"true\"/>");
		povOptions += _S("<option name=\"acp.portal.name\" value=\"") + HtmlParser::instance()->encode(portalName) + _S("\"/>");
		povOptions += _S("<option name=\"acp.portal.description\" value=\"") + HtmlParser::instance()->encode(portalDescription) + _S("\"/>");						
		povOptions += _S("</options>");

		String sql = _S("update os_users set options=") + Convert::toSQL(povOptions) + _S(" where id=") + Convert::toSQL(userID.toUTF16()) + _S(";");
		database->execute(sql);
	}

	// Rename changed ID
	renameIDS(database);

	// Update contents	
	{
		if(upgradeContentOML(database, _S("os_calendar_events"), _S("content"), false) == false)
			return false;
		if(upgradeContentOML(database, _S("os_files"), _S("content"), false) == false)
			return false;
		if(upgradeContentOML(database, _S("os_models"), _S("content"), false) == false)
			return false;
		if(upgradeContentOML(database, _S("os_polls"), _S("content"), false) == false)
			return false;
		if(upgradeContentOML(database, _S("os_posts"), _S("content"), false) == false)
			return false;
		if(upgradeContentOML(database, _S("os_texts"), _S("content"), false) == false)
			return false;
		if(upgradeContentOML(database, _S("os_users"), _S("mark"), false) == false)
			return false;
		if(upgradeContentOML(database, _S("os_instances"), _S("data"), true) == false)
			return false;
		if(upgradeContentOML(database, _S("os_sections"), _S("data"), true) == false)
			return false;
		if(upgradeContentOML(database, _S("os_sections"), _S("component"), false) == false)
			return false;
		if(upgradeContentOML(database, _S("os_instances"), _S("module"), false) == false)
			return false;
	}	

	String filename = utils::makeFilePath(Options::instance()->getLogPath(), _S("migration_") + database->getPortal()->getPortalID().toWide() + _S(".log"));

	shared_ptr<File> file(OS_NEW File());
	if(file->open(filename, File::ofWrite) == false)
		return false;

	std::string debugAscii = m_DebugLog.to_ascii();
	file->write(debugAscii.data(), static_cast<uint32>(debugAscii.size()));

	file->close();

	return true;
}
void ThreadedOptFossilCollManager::checkpoint(const VTime &checkTime,
		const ObjectID &objId, const unsigned int &threadId) {
	int time = checkTime.getApproximateIntTime();
	int id = objId.getSimulationObjectID();

	// If the time is less than the last checkpoint time, then save at the last
	// checkpoint time again.
	updateCheckpointTime(id, time);

	while (time >= nextCheckpointTime[id]) {
		utils::debug << mySimManager->getSimulationManagerID()
				<< " - Checkpointing object " << id << " at " << time << endl;
		int highestNextCheckpointTime = nextCheckpointTime[0];
		for (int iter = 1; iter < mySimManager->getNumberOfSimulationObjects(); iter++) {
			if (nextCheckpointTime[iter] > highestNextCheckpointTime)
				highestNextCheckpointTime = nextCheckpointTime[iter];
		}

		vector<State *> *states;
		if (nextCheckpointTime[id] == highestNextCheckpointTime) {
			// No states have been check pointed for this time yet.
			// Thus we create a state vector for all the objects
			utils::debug << "Creating new states to be saved at time "
					<< nextCheckpointTime[id] << endl;
			states = new vector<State*> (
					mySimManager->getNumberOfSimulationObjects(), NULL);
			checkpointedStates.insert(
					pair<int, vector<State*> *> (nextCheckpointTime[id], states));
		} else {
			// States have been saved for other objects but not this object at this time
			// or a roll back in this object is causing this to happen.
			utils::debug
					<< "Adding the current state of the object to checkpointedStates "
					<< nextCheckpointTime[id] << endl;

			map<int, vector<State*>*>::iterator it = checkpointedStates.find(
					nextCheckpointTime[id]);
			states = it->second;
		}

		SimulationObject *object = mySimManager->getObjectHandle(objId);

		// Save the state of the object at the checkpoint time.
		State *newState = object->allocateState();
		newState->copyState(object->getState());
		(*states)[id] = newState;

		lastCheckpointTime[id] = nextCheckpointTime[id];
		nextCheckpointTime[id] += checkpointPeriod;

		stringstream filename;
		filename << ckptFilePath << "LP"
				<< mySimManager->getSimulationManagerID() << "."
				<< lastCheckpointTime[id] << "." << id;

		ofstream ckFile(filename.str().c_str(), ofstream::binary);
		if (!ckFile.is_open()) {
			cerr << mySimManager->getSimulationManagerID()
					<< " - Could not open file: " << filename.str()
					<< ", aborting simulation." << endl;
			abort();
		}

		mySimManager->getOutputManagerNew()->saveOutputCheckpoint(&ckFile,
				objId, lastCheckpointTime[id], threadId);
		ckFile.close();
	}
}
Esempio n. 27
0
void IdeMailBox::renderMessage(const ObjectID &id, shared_ptr<XMLNode> node)
{
	shared_ptr<ObjectsMessage> message;

	shared_ptr<DataLocalMessage> local_message = getPortal()->getMessenger()->getMessage(getPage()->getDatabase(), getSessionAccount(), id, true);
	if(local_message != nullptr)
	{
		// Decodifica il messaggio
		message = local_message->decode(getSessionAccount()->getPrivateKey());
	}

	if(message == nullptr)
		return;

	shared_ptr<OMLContext> messageContext = getPage()->parseOmlEx(message->body, false, true, getSecure(), false, omlRenderModeOsiris, String::EMPTY, String::EMPTY);
	if(messageContext == nullptr)
		return;

	shared_ptr<XMLPortalExporter> messageExporter(OS_NEW XMLPortalExporter(node, getPage(), XMLPortalExporter::emFull));
	local_message->exportXML(messageExporter, message->subject, messageContext->getOutput(), messageContext->getSecureCheck());

	shared_ptr<XMLNode> node_actions = node->addChild(_S("actions"));

	shared_ptr<ObjectsUser> author = objects_user_cast(getPage()->getObject(local_message->author));
	if(author != nullptr)
	{
		shared_ptr<XMLNode> action_reply = node_actions->addChild(_S("action"));
		action_reply->setAttributeString(_S("name"), _S("reply"));

		ordered_map<std::wstring, std::wstring> params;
		params.set(OS_URL_PARAM_QUOTE, (_W("re: ") + message->subject).to_wide());
		action_reply->setAttributeString(_S("href"), getPortal()->getSendMessageLink(author->id, params));
	}

	if(local_message->folder == static_cast<uint32>(messageFolderTrash))
	{
		shared_ptr<XMLNode> action_delete = node_actions->addChild(_S("action"));
		action_delete->setAttributeString(_S("name"), _S("restore"));
		action_delete->setAttributeString(_S("href"), getEventCommand(EVENT_ONRESTOREMESSAGE, id.toUTF16()));
	}
	else
	{
		shared_ptr<XMLNode> action_delete = node_actions->addChild(_S("action"));
		action_delete->setAttributeString(_S("name"), _S("delete"));
		action_delete->setAttributeString(_S("href"), getEventCommand(EVENT_ONDELETEMESSAGE, id.toUTF16()));
	}

	if(getSecure())
	{
		bool unsafe = messageContext->getSecureCheck() == false;
		if(unsafe == false)
		{
			shared_ptr<ObjectsUser> messageAuthor = objects_user_cast(getPage()->getObject(local_message->author));
			if(messageAuthor != nullptr)
			{
				shared_ptr<OMLContext> markContext = getPage()->parseOmlEx(messageAuthor->mark, false, true, getSecure(), false, omlRenderModeOsiris, String::EMPTY, String::EMPTY);
				if(markContext != nullptr)
					unsafe = markContext->getSecureCheck() == false;
			}
		}

		if(unsafe)
		{
			shared_ptr<XMLNode> action_delete = node_actions->addChild(_S("action"));
			action_delete->setAttributeString(_S("name"), _S("show"));
			action_delete->setAttributeString(_S("href"), getPortal()->getPrivateMessageLink(id, false));
		}
	}
}
Esempio n. 28
0
//bool EntitiesEntity::_loadObject(const shared_ptr<IPortalDatabase> &database, shared_ptr<ObjectsIRevisionable> object)
bool EntitiesEntity::load(const shared_ptr<IPortalDatabase> &database, const EntityID & id)
{
	OS_TIMER_PERFORMANCE(TP, _S("Entity::_loadObject"));
	OS_LOCK(m_cs);

#ifndef OS_TODOCIP
	shared_ptr<ObjectsIRevisionable> object = objects_revisionable_cast(database->getPortal()->getObject(database, id.toUTF16()));
	m_primary = object;
	//OS_ASSERT(getEntityID() == id);
#endif

	if(database->getPortal()->getSnapshotManager()->m_enableEnsureLoadingEntity)
		database->getPortal()->getSnapshotManager()->ensure(database, id);

	DataTable result;
	// TOCLEAN_SNAPSHOT_SCORE
	//String sql = String::format(_S("select current,visible,score,depth,parent,section,stability_date from os_snapshot_objects where reference='%S'").c_str(), m_primary->id->toUTF16().c_str());
	String sql = String::format(_S("select type,current,visible,depth,parent,section,stability_date from os_snapshot_objects where entity='%S'").c_str(), id.toUTF16().c_str());
	database->execute(sql, result);
	if(!result.hasRow(0))
	{
		clear();
		return false;
	}
	else
	{
		ObjectID currentID = static_cast<String>(result.get(0,_S("current"))).to_ascii();
		m_type = Convert::toObjectType(static_cast<uint32>(result.get(0,_S("type"))));
		m_visible = result.get(0,_S("visible"));
		//m_score = *result.get(0,_S("score")); // TOCLEAN_SNAPSHOT_SCORE
		m_depth = result.get(0,_S("depth"));
		m_parent = static_cast<String>(result.get(0,_S("parent"))).to_ascii();
		m_section = static_cast<String>(result.get(0,_S("section"))).to_ascii();
		m_stabilityDate = String(result.get(0,_S("stability_date")));

		if(id == ObjectsSystem::instance()->getRootID())
			//m_current = objects_revisionable_cast(database->getPortal()->getObject(database, ObjectsSystem::instance()->getRootID().toObjectID()));
			m_current = ObjectsSection::getRootSection();
		else
		{		
#ifdef OS_TODOCIP
			/*
			if(currentID.empty())
				return false;
			m_current = objects_revisionable_cast(database->getPortal()->getObject(database, currentID));
			if(m_current == nullptr)
				return false;				
			*/

			if(currentID.empty() == false)
				m_current = objects_revisionable_cast(database->getPortal()->getObject(database, currentID));
#else
			if(currentID.empty())
			{
				m_current.reset();
				// OS_ASSERT(m_parent == ObjectsSystem::instance()->getSkippedID());
				// No, dato che la getEntity non fa + l'ensure, può succedere che carica un oggetto non stabilizzato.
				m_visible = false;
			}
			else
				m_current = objects_revisionable_cast(database->getPortal()->getObject(database, currentID));
#endif
		}

		return true;
	}
}
void ThreadedCostAdaptiveStateManager::saveState(const VTime& currentTime,
		unsigned int eventNumber, SimulationObject *object,
		const ObjectID senderId, int threadID) {
	ObjectID *currentObjectID = object->getObjectID();
	unsigned int simObjectID = currentObjectID->getSimulationObjectID();

	// The period is only recalculated after the specified number of events.
	if (forwardExecutionLength[simObjectID]
			< eventsBetweenRecalculation[simObjectID]) {
		forwardExecutionLength[simObjectID]++;
	} else {
		calculatePeriod(object);
	}
	if (mySimulationManager->isRollbackJustCompleted(simObjectID)) {
		//	cout << "Last Rollback Time ::{{{{{{{{{{{{{{{{{}}}}}}}} "
		//			<< *(lastRollbackTime[simObjectID]) << endl;
		multiset<SetObject<State> >::iterator iter_end =
				myStateQueue[simObjectID].end();
		/*cout << "Current Num = " << eventNumber << ":::::  Old Number = "
		 << rollbackEventNumber[simObjectID] << endl;*/
		if (*(lastRollbackTime[simObjectID]) == currentTime && eventNumber
				<= rollbackEventNumber[simObjectID]) {
			//		cout << " Need to update the Event Number in the state ::::"
			//				<< eventNumber << endl;
			ThreadedStateManagerImplementationBase::getStateQueueLock(threadID,
					simObjectID);
			State *newState = object->allocateState();
			newState->copyState(object->getState());
			SetObject<State> stateObject(currentTime, newState, eventNumber,
					senderId.getSimulationObjectID(),
					senderId.getSimulationObjectID());
			//object->deallocateState((*iter_end).getElement());
			//myStateQueue[simObjectID].erase(iter_end);
			// look up the state queue of the simulation object and insert the
			// newly allocated state object

			myStateQueue[simObjectID].insert(stateObject);
			//		cout << "Saving at the Time Stamp :::::"
			//				<< currentTime.getApproximateIntTime() << endl;
			//		cout << "Imm. After savig the EventId ::::;"
			//				<< stateObject.getEventNumber() << endl;
			// *iter_end = stateObject;
			ThreadedStateManagerImplementationBase::releaseStateQueueLock(
					threadID, simObjectID);
		}
		mySimulationManager->resetRollbackCompletedStatus(simObjectID);
		return;
	}
	if (periodCounter[simObjectID] <= 0) {
		// we need to first allocate a state. Copy the current state into
		// this newly created state. Then allocate a state object and
		// fill in the current time and a pointer to the newly copied
		// current state.
		State *newState = object->allocateState();
		newState->copyState(object->getState());
		SetObject<State> stateObject(currentTime, newState, eventNumber,
				senderId.getSimulationObjectID(),
				senderId.getSimulationObjectID());

		// look up the state queue of the simulation object and insert the
		// newly allocated state object
		ThreadedStateManagerImplementationBase::getStateQueueLock(threadID,
				simObjectID);
		myStateQueue[simObjectID].insert(stateObject);
		//	cout << "Saving at the Time Stamp :::::"
		//			<< currentTime.getApproximateIntTime()
		//			<< "  With Event Number :::: " << eventNumber
		//			<< "  With senderObjectId :::: "
		//			<< senderId.getSimulationObjectID() << endl;

		multiset<SetObject<State> >::iterator iter_end =
				myStateQueue[simObjectID].end();
		iter_end--;
		/*cout << "Imm. After saving the EventId ::::::: "
		 << (*iter_end).getEventNumber() << endl;
		 cout << "Imm. After saving the SenderId ::::::: "
		 << (*iter_end).getsenderObjectId() << endl;*/

		ThreadedStateManagerImplementationBase::releaseStateQueueLock(threadID,
				simObjectID);
		// reset period counter to state period
		periodCounter[simObjectID] = objectStatePeriod[simObjectID];
	} else {
		// decrement period counter
		periodCounter[simObjectID] = periodCounter[simObjectID] - 1;
	}
}