Example #1
0
 /**
  * ...
  *
  * @return	array	If returns TRUE, upgrader will proceed to next step. If it returns any other value, it will set this as the value of the 'extra' GET parameter and rerun this step (useful for loops)
  */
 public function step1()
 {
     /* These changes should have been done by the 3.1.0 upgrader, but I forgot. */
     if (!\IPS\Db::i()->checkForIndex('membermap_markers_groups', 'group_position')) {
         \IPS\Db::i()->addIndex('membermap_markers_groups', array('type' => 'key', 'name' => 'group_position', 'columns' => array('group_position')));
     }
     if (!\IPS\Db::i()->checkForIndex('membermap_markers', 'marker_member_id')) {
         \IPS\Db::i()->addIndex('membermap_markers', array('type' => 'key', 'name' => 'marker_member_id', 'columns' => array('marker_member_id')));
     }
     if (!\IPS\Db::i()->checkForIndex('membermap_markers', 'marker_parent_id')) {
         \IPS\Db::i()->addIndex('membermap_markers', array('type' => 'key', 'name' => 'marker_parent_id', 'columns' => array('marker_parent_id')));
     }
     \IPS\Db::i()->changeColumn('membermap_markers', 'marker_open', array('name' => 'marker_open', 'type' => 'tinyint', 'length' => 1, 'allow_null' => false, 'default' => 0));
     \IPS\Db::i()->update('membermap_markers', array('marker_open' => 0), 'marker_open IS NULL');
     \IPS\Task::queue('membermap', 'RebuildCache', array('class' => '\\IPS\\membermap\\Map'), 1, array('class'));
     return TRUE;
 }
Example #2
0
 /**
  * Rewrite cache file
  * 
  * @return	array	Parsed list of markers
  */
 public function recacheJsonFile()
 {
     /* The upgrader kept firing this off whenever a group/marker was saved. */
     if (isset(\IPS\Request::i()->controller) and \IPS\Request::i()->controller == 'applications') {
         return;
     }
     $totalMarkers = 0;
     $memberMarkers = array();
     $customMarkers = array();
     try {
         $totalMarkers = \IPS\Db::i()->select('COUNT(*)', 'membermap_markers')->first();
     } catch (\Exception $ex) {
     }
     /* Trigger the queue if the marker count is too large to do in one go. */
     /* We'll hardcode the cap at 4000 now, that consumes roughly 50MB */
     /* We'll also see if we have enough memory available to do it */
     $currentMemUsage = memory_get_usage(TRUE);
     $memoryLimit = intval(ini_get('memory_limit'));
     $useQueue = false;
     if ($memoryLimit > 0) {
         $howMuchAreWeGoingToUse = $totalMarkers * 0.02;
         /* ~0.02MB pr marker */
         $howMuchAreWeGoingToUse += 10;
         /* Plus a bit to be safe */
         $howMuchDoWeHaveLeft = $memoryLimit - ceil($currentMemUsage / 1024 / 1024);
         if ($howMuchDoWeHaveLeft < $howMuchAreWeGoingToUse) {
             $useQueue = true;
         }
     }
     if ($totalMarkers > 4000) {
         $useQueue = true;
     }
     if ($useQueue or defined('MEMBERMAP_FORCE_QUEUE') and MEMBERMAP_FORCE_QUEUE) {
         \IPS\Task::queue('membermap', 'RebuildCache', array('class' => '\\IPS\\membermap\\Map'), 1, array('class'));
         return;
     }
     $selectColumns = array('mm.*', 'mg.*', 'm.member_id', 'm.name', 'm.members_seo_name', 'm.member_group_id', 'm.pp_photo_type', 'm.pp_main_photo', 'm.pp_thumb_photo');
     if (\IPS\Settings::i()->allow_gravatars) {
         $selectColumns[] = 'm.pp_gravatar';
         $selectColumns[] = 'm.email';
         $selectColumns[] = 'm.members_bitoptions';
     }
     /* Remember to update the queue too */
     $_markers = \IPS\Db::i()->select(implode(',', $selectColumns), array('membermap_markers', 'mm'), array('marker_open=1'), 'mg.group_position ASC, mm.marker_id DESC')->join(array('membermap_markers_groups', 'mg'), 'mm.marker_parent_id=mg.group_id')->join(array('core_members', 'm'), 'mm.marker_member_id=m.member_id');
     foreach ($_markers as $marker) {
         if ($marker['group_type'] == 'member') {
             $memberMarkers[] = $marker;
         } else {
             $customMarkers[] = $marker;
         }
     }
     $markers = $this->formatMemberMarkers($memberMarkers);
     $custMarkers = $this->formatCustomMarkers($customMarkers);
     $markers = array_merge($markers, $custMarkers);
     $markers = array_chunk($markers, 500);
     $this->deleteCacheFiles();
     $fileCount = 0;
     foreach ($markers as $chunk) {
         touch(\IPS\ROOT_PATH . '/datastore/membermap_cache/membermap-' . $fileCount . '.json');
         chmod(\IPS\ROOT_PATH . '/datastore/membermap_cache/membermap-' . $fileCount . '.json', \IPS\IPS_FILE_PERMISSION);
         \file_put_contents(\IPS\ROOT_PATH . '/datastore/membermap_cache/membermap-' . $fileCount . '.json', json_encode(array('markers' => $chunk, 'memUsage' => (memory_get_usage(TRUE) - $currentMemUsage) / 1024 . 'kB')));
         $fileCount++;
     }
     /* Store the timestamp of the cache to force the browser to purge its local storage */
     \IPS\Data\Store::i()->membermap_cacheTime = time();
 }
Example #3
0
 /**
  * Clean up
  */
 public function step4()
 {
     unset($_SESSION['_membermapMemberGroupId']);
     /* Restore content in the search index */
     \IPS\Task::queue('core', 'RebuildSearchIndex', array('class' => 'IPS\\membermap\\Markers\\Markers'));
     try {
         // \IPS\Db::i()->dropTable( 'membermap_members', TRUE ); # Want to keep this table as backup for a couple of versions
         \IPS\Db::i()->dropColumn('core_groups', 'g_membermap_canAdd');
         \IPS\Db::i()->dropColumn('core_groups', 'g_membermap_canEdit');
         \IPS\Db::i()->dropColumn('core_groups', 'g_membermap_canDelete');
     } catch (\IPS\Db\Exception $e) {
     }
     #meh
     return TRUE;
 }