Skip to content

Commit

Permalink
More memory management changes.
Browse files Browse the repository at this point in the history
Just editing a few more files to use less memory from storing data
in variables.
  • Loading branch information
mastacontrola committed Jan 2, 2017
1 parent 99289e3 commit 137d829
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 93 deletions.
2 changes: 1 addition & 1 deletion packages/web/lib/fog/system.class.php
Expand Up @@ -53,7 +53,7 @@ private static function _versionCompare()
public function __construct()
{
self::_versionCompare();
define('FOG_VERSION', '941451');
define('FOG_VERSION', '992916');
define('FOG_SCHEMA', 244);
define('FOG_BCACHE_VER', 111);
define('FOG_SVN_REVISION', 6052);
Expand Down
Expand Up @@ -62,13 +62,13 @@ public function __construct()
try {
$strSetup = "%s|%s|%s|%s|%s|%s|%s";
ob_start();
$Capones = self::getClass('CaponeManager')
foreach ((array)self::getClass('CaponeManager')
->find(
array(
'key' => trim(base64_decode($_REQUEST['key']))
)
);
foreach ((array)$Capones as &$Capone) {
) as &$Capone
) {
$Image = $Capone->getImage();
if (!$Image->isValid()) {
continue;
Expand Down
5 changes: 3 additions & 2 deletions packages/web/lib/plugins/ldap/hooks/ldappluginhook.hook.php
Expand Up @@ -90,11 +90,12 @@ public function checkAddUser($arguments)
)
);
}
$ldaps = self::getClass('LDAPManager')->find();
/**
* Create our new user (initially at least
*/
foreach ((array)$ldaps as &$ldap) {
foreach ((array)self::getClass('LDAPManager')
->find() as &$ldap
) {
$access = $ldap->authLDAP($user, $pass);
unset($ldap);
switch ($access) {
Expand Down
113 changes: 79 additions & 34 deletions packages/web/lib/plugins/location/hooks/addlocationhost.hook.php
Expand Up @@ -91,22 +91,31 @@ public function hostData($arguments)
}
$arguments['templates'][4] = '${location}<br/><small>${deployed}</small>';
foreach ((array)$arguments['data'] as $index => &$vals) {
$Locations = self::getClass('LocationAssociationManager')->find(
array(
'hostID' => $vals['id']
)
$find = array(
'hostID' => $vals['id']
);
$Locations = self::getSubObjectIDs(
'LocationAssociation',
$find,
'locationID'
);
if (count($Locations) !== 1) {
$cnt = self::getClass('LocationManager')
->count(
array('id' => $Locations)
);
if ($cnt !== 1) {
$arguments['data'][$index]['location'] = '';
continue;
}
foreach ((array)$Locations as &$Location) {
foreach ((array)self::getClass('LocationManager')
->find(array('id' => $Locations)) as &$Location
) {
$arguments['data'][$index]['location'] = $Location
->getLocation()
->get('name');
unset($Location);
}
unset($vals);
unset($Locations);
}
}
/**
Expand All @@ -126,25 +135,27 @@ public function hostFields($arguments)
if ($node != 'host') {
return;
}
$Locations = self::getClass('LocationAssociationManager')->find(
array(
'hostID' => $arguments['Host']->get('id')
)
);
$Locations = self::getSubObjectIDs(
'LocationAssociation',
array(
'hostID' => $arguments['Host']->get('id')
),
'locationID'
);
$cnt = count($Locations);
$cnt = self::getClass('LocationManager')->count(
array(
'id' => $Locations
)
);
if ($cnt !== 1) {
$locID = 0;
} else {
$Locations = self::getSubObjectIDs(
'Location',
array('id' => $Locations)
);
$locID = array_shift($Locations);
}
unset($Locations);
$this->arrayInsertAfter(
_('Host Product Key'),
$arguments['fields'],
Expand Down Expand Up @@ -189,6 +200,13 @@ public function hostAddLocation($arguments)
'hostID' => $arguments['Host']->get('id')
)
);
$cnt = self::getClass('LocationManager')
->count(
array('id' => $_REQUEST['location'])
);
if ($cnt !== 1) {
return;
}
self::getClass('LocationAssociation')
->set('hostID', $arguments['Host']->get('id'))
->load('hostID')
Expand Down Expand Up @@ -225,17 +243,26 @@ public function hostExport($arguments)
if (!in_array($this->node, (array)$_SESSION['PluginsInstalled'])) {
return;
}
$Locations = self::getClass('LocationAssociationManager')->find(
array(
'hostID' => $arguments['Host']->get('id')
)
$find = array(
'hostID' => $arguments['Host']->get('id')
);
$Locations = self::getSubObjectIDs(
'LocationAssociation',
$find,
'locationID'
);
$cnt = self::getClass('LocationManager')->count(
array('id' => $Locations)
);
if (count($Locations) < 1) {
if ($cnt !== 1) {
$arguments['report']->addCSVCell('');
return;
}
foreach ((array)$Locations as &$Location) {
foreach ((array)self::getClass('LocationManager')
->find(array('id' => $Locations)) as &$Location
) {
$arguments['report']->addCSVCell(
$Location->getLocation()->get('id')
$Location->get('id')
);
unset($Location);
}
Expand Down Expand Up @@ -271,18 +298,25 @@ public function hostEmailHook($arguments)
if (!in_array($this->node, (array)$_SESSION['PluginsInstalled'])) {
return;
}
$Locations = self::getClass('LocationAssociationManager')->find(
$Locations = self::getSubObjectIDs(
'LocationAssociation',
array(
'hostID' => $arguments['Host']->get('id')
)
),
'locationID'
);
if (count($Locations) < 1) {
$cnt = self::getClass('LocationManager')
->count(array('id' => $Locations));
if ($cnt !== 1) {
$locName = '';
}
foreach ((array)$Locations as $Location) {
$locName = $Location->getLocation()->get('name');
unset($Location);
break;
} else {
foreach ((array)self::getClass('LocationManager')
->find(array('id' => $Locations)) as $Location
) {
$locName = $Location->get('name');
unset($Location);
break;
}
}
$this->arrayInsertAfter(
"\nSnapin Used: ",
Expand All @@ -309,6 +343,11 @@ public function hostRegister($arguments)
if (!in_array($this->node, (array)$_SESSION['PluginsInstalled'])) {
return;
}
$cnt = self::getClass('LocationManager')
->count(array('id' => $_REQUEST['location']));
if ($cnt !== 1) {
return;
}
self::getClass('LocationAssociation')
->set('hostID', $arguments['Host']->get('id'))
->set('locationID', $_REQUEST['location'])
Expand All @@ -334,17 +373,23 @@ public function hostInfoExpose($arguments)
if (!in_array($this->node, (array)$_SESSION['PluginsInstalled'])) {
return;
}
$Locations = self::getClass('LocationAssociationManager')->find(
$Locations = self::getSubObjectIDs(
'LocationAssociation',
array(
'hostID' => $arguments['Host']->get('id')
)
),
'locationID'
);
if (count($Locations) < 1) {
$cnt = self::getClass('LocationManager')
->count(array('id' => $Locations));
if ($cnt !== 1) {
$arguments['repFields']['location'] = '';
return;
}
foreach ((array)$Locations as &$Location) {
foreach ((array)self::getClass('LocationManager')
->find(array('id' => $Locations)) as &$Location
) {
$arguments['repFields']['location'] = $Location
->getLocation()
->get('name');
unset($Location);
}
Expand Down
16 changes: 11 additions & 5 deletions packages/web/lib/plugins/location/hooks/addlocationtasks.hook.php
Expand Up @@ -84,17 +84,23 @@ public function tasksActiveData($arguments)
$arguments['templates'][4] = '${location}';
$arguments['attributes'][4] = array('class'=>'r');
foreach ((array)$arguments['data'] as $i => &$data) {
$Locations = self::getClass('LocationAssociationManager')->find(
$Locations = self::getSubObjectIDs(
'LocationAssociation',
array(
'hostID' => $data['host_id']
)
),
'locationID'
);
if (count($Locations) < 1) {
$cnt = self::getClass('LocationManager')
->count(array('id' => $Locations));
if ($cnt !== 1) {
$arguments['data'][$i]['location'] = '';
continue;
}
foreach ((array)$Locations as &$Location) {
foreach ((array)self::getClass('LocationManager')
->find(array('id' => $Locations)) as &$Location
) {
$arguments['data'][$i]['location'] = $Location
->getLocation()
->get('name');
unset($Location);
}
Expand Down
45 changes: 24 additions & 21 deletions packages/web/lib/plugins/location/hooks/changeitems.hook.php
Expand Up @@ -67,11 +67,17 @@ public function storageNodeSetting($arguments)
'hostID' => $arguments['Host']->get('id')
)
);
$Locations = self::getSubObjectIDs(
'LocationAssociation',
array(
'hostID' => $arguments['Host']->get('id')
),
'locationID'
);
$method = false;
foreach ((array)$Locations as $Location) {
if (!$Location->isValid()) {
continue;
}
foreach ((array)self::getClass('LocationManager')
->find(array('id' => $Locations)) as $Location
) {
$Host =& $arguments['Host'];
$Task = $Host->get('task');
$TaskType =& $arguments['TaskType'];
Expand All @@ -88,22 +94,19 @@ public function storageNodeSetting($arguments)
$method = 'getMasterStorageNode';
}
$StorageGroup = $Location
->getLocation()
->getStorageGroup();
if ($StorageGroup->isValid()) {
if (!isset($arguments['snapin'])
|| ($arguments['snapin'] === true
&& self::getSetting('FOG_SNAPIN_LOCATION_SEND_ENABLED') > 0)
) {
$arguments['StorageNode'] = $Location
->getLocation()
->getStorageNode();
}
if (!$method) {
continue;
}
$arguments['StorageNode'] = $Location
->getLocation()
->getStorageGroup()
->{$method}();
}
Expand All @@ -125,17 +128,17 @@ public function storageGroupSetting($arguments)
if (!$arguments['Host']->isValid()) {
return;
}
$Locations = self::getClass('LocationAssociationManager')->find(
$Locations = self::getSubObjectIDs(
'LocationAssociation',
array(
'hostID' => $arguments['Host']->get('id')
)
),
'locationID'
);
foreach ((array)$Locations as &$Location) {
if (!$Location->isValid()) {
continue;
}
foreach ((array)self::getClass('LocationManager')
->find(array('id' => $Locations)) as &$Location
) {
$StorageGroup = $Location
->getLocation()
->getStorageGroup();
if (!$StorageGroup->isValid()) {
continue;
Expand All @@ -159,20 +162,20 @@ public function bootItemSettings($arguments)
if (!$arguments['Host']->isValid()) {
return;
}
$Locations = self::getClass('LocationAssociationManager')->find(
$Locations = self::getSubObjectIDs(
'LocationAssociation',
array(
'hostID' => $arguments['Host']->get('id')
)
),
'locationID'
);
foreach ((array)$Locations as $Location) {
if (!$Location->isValid()) {
continue;
}
foreach ((array)self::getClass('LocationManager')
->find(array('id' => $Locations)) as $Location
) {
if (!$Location->isTFTP()) {
continue;
}
$StorageNode = $Location
->getLocation()
->getStorageNode();
if (!$StorageNode->isValid()) {
continue;
Expand Down
Expand Up @@ -103,11 +103,9 @@ public function __construct()
public function onEvent($event, $data)
{
self::$elements = $data;
$objects = self::getClass('PushbulletManager')
->find();
array_map(
self::$eventloop,
(array)$objects
(array)self::getClass('PushbulletManager')->find()
);
}
}

0 comments on commit 137d829

Please sign in to comment.