function updateUser($user, &$success, &$failure, &$total) { $this->logger->log("Updating data for " . $user->username, Zend_Log::INFO); // Assign the proper shard id Zend_Registry::set("shard", $user->id); // Get the user sources $sourcesTable = new Sources(); $sources = $sourcesTable->getSources(); if (!$sources) { echo "No sources found to update.\r\n"; $this->logger->log("No sources found to update.", Zend_Log::INFO); die; } // Log an entry $this->logger->log("Updating {$user->username}", Zend_Log::INFO); shuffle($sources); $total = $total + count($sources); foreach ($sources as $source) { if ($source['service'] == 'stuffpress') { continue; } if (!$source['enabled']) { continue; } if (!is_null($this->cl_source) && $source['service'] != $this->cl_source) { continue; } $model = SourceModel::newInstance($source['service'], $source); if (!$model->isActive()) { echo "Skipping unactive source {$source['service']}.\r\n "; continue; } try { if ($source['imported']) { echo "Updating source {$source['service']} for user {$user->username} [" . ($success + $failure) . "/{$total}] ({$source['id']})...."; $items = $model->updateData(); $model->onNewItems($items); echo " found " . count($items) . " items\r\n"; } else { echo "Importing source {$source['service']} ({$source['id']}).\r\n"; $items = $model->importData(); } $success++; } catch (Exception $e) { echo "Could not update source {$source['id']}: " . $e->getMessage(); $this->logger->log("Could not update source {$source['id']}: " . $e->getMessage(), Zend_Log::ERR); echo $e->getTraceAsString(); $failure++; } } }
public function indexAction() { // TODO Needs to display more info about the source and nicer string // Fetch the list of configured services for this user $table = new Sources(); $sources = $table->getSources(); $s = array(); if ($sources) { foreach ($sources as $source) { if ($source['service'] == 'stuffpress') { continue; } $model = SourceModel::newInstance($source['service']); $model->setSource($source); $e = array(); $e['service'] = $model->getServicePrefix(); $e['url'] = $model->getServiceURL(); $e['name'] = $model->getServiceName(); $e['description'] = $model->getServiceDescription(); $e['account'] = $model->getAccountName(); $e['id'] = $source['id']; $s[] = $e; } } $this->view->sources = $s; // Fetch the list of available services $services = array(); foreach (Sources::getAvailableSources() as $c) { if ($c == 'stuffpress') { continue; } $model = SourceModel::newInstance($c); if (!$model->isActive()) { continue; } $e['service'] = $c; $e['name'] = $model->getServiceName(); $e['description'] = $model->getServiceDescription(); $services[] = $e; } $this->view->services = $services; // Get errror and status messages $this->view->status_messages = $this->getStatusMessages(); $this->view->error_messages = $this->getErrorMessages(); $this->view->suspended = $this->_application->user->is_suspended; // Add common stuff $this->common(); $this->view->headScript()->appendFile('js/storytlr/effects.js'); $this->view->headScript()->appendFile('js/controllers/services.js'); }
public function indexAction() { $application = Stuffpress_Application::getInstance(); // If we are not logged in, we have a problem if ($application->role != 'guest') { $sources = new Sources(array(Stuffpress_Db_Table::USER => $application->user->id)); $mysources = $sources->getSources(); if (count($mysources) > 1) { return $this->_forward('index', 'post', 'admin'); } else { return $this->_forward('index', 'services', 'admin'); } } else { return $this->_forward('index', 'auth', 'admin'); } }
public function keywordAction() { // Action parameters $search = $this->getRequest()->getParam("search"); // A bit of filtering $search = substr($search, 0, 50); // Get all the items; if we are an admin, we also get the hidden one $data = new Data(); $sourcesTable = new Sources(); $sources = $sourcesTable->getSources(); $items = array(); foreach ($sources as $source) { $s = SourceModel::newInstance($source['service'], $source); $index = $s->getSearchIndex(); $prefix = $s->getServicePrefix(); $id = $s->getID(); if ($index != '') { $r = $data->search($id, $prefix, $index, $search, $this->_admin); if ($r) { $items = array_merge($items, $r); } } } // Sort the result of the search $sorter = new Stuffpress_SortItems(); $sorter->sort($items, 1); // Prepare the common elements $this->common(); // Add specifics entries $this->view->search = $search; $this->view->items = $items; $this->view->models = $this->getModels(); // Set page title $title = $this->_properties->getProperty('title'); $subtitle = $this->_properties->getProperty('subtitle'); $separator = $title ? "|" : ""; $this->view->headTitle("{$title} {$separator} Search results for {$search}"); // Add specific styles and javascripts $this->view->headScript()->appendFile('js/controllers/timeline.js'); $this->view->headLink()->appendStylesheet('style/lightbox.css'); // Render the index $this->render('index'); }
public function indexAction() { // Get, check and setup the parameters if (!($widget_id = $this->getRequest()->getParam("id"))) { throw new Stuffpress_Exception("No widget id provided to the widget controller"); } // Verify if the requested widget exist and get its data $widgets = new Widgets(); if (!($widget = $widgets->getWidget($widget_id))) { throw new Stuffpress_Exception("Invalid widget id"); } // Get all sources configured for that user $sources = new Sources(array(Stuffpress_Db_Table::USER => $widget['user_id'])); $mysources = $sources->getSources(); // If sources are configured, get the links for each source $links = array(); if ($mysources) { foreach ($mysources as $source) { if (!($source['public'] && $source['enabled'])) { continue; } if ($source['service'] == 'stuffpress') { continue; } $model = SourceModel::newInstance($source['service']); $model->setSource($source); $link['prefix'] = $model->getServicePrefix(); $link['url'] = $model->getServiceURL(); $link['name'] = $model->getTitle(); $links[] = $link; } } // Get the widget properties $properties = new WidgetsProperties(array(Properties::KEY => $widget_id)); $title = $properties->getProperty('title'); $this->view->title = $title ? $title : "My 2.0 Life"; // Prepare the view for rendering $this->view->links = $links; }
public function indexAction() { // Fetch the list of configured services for this user $table = new Sources(); $data = new Data(); $sources = $table->getSources(); $mysources = array(); if ($sources) { foreach ($sources as $source) { $model = SourceModel::newInstance($source['service']); $model->setSource($source); $e = array(); $e['prefix'] = $model->getServicePrefix(); $e['name'] = $model->getServiceName(); $e['description'] = $model->getServiceDescription(); $e['account'] = $model->getAccountName(); $e['id'] = $source['id']; $mysources[] = $e; } } $this->view->sources = $mysources; }
$logger->addWriter(new Zend_Log_Writer_Stream($log_root . '/updates.log')); Zend_Registry::set('logger', $logger); // Prepare models we need to access echo "Memory usage on startup: " . memory_get_usage() . "\r\n"; $usersTable = new Users(); // Get the user $user = $usersTable->getUserFromUsername($cl_user); if (!$user || $user->is_suspended) { echo "User {$user->username} is suspended.\r\n"; $logger->log("User {$user->username} is suspended.\r\n", Zend_Log::INFO); die; } Zend_Registry::set("shard", $user->id); // Get the user sources $sourcesTable = new Sources(); $sources = $sourcesTable->getSources(); if (!$sources) { echo "No sources found to update.\r\n"; $logger->log("No sources found to update.", Zend_Log::INFO); die; } // Log an entry $logger->log("Updating {$user->username}", Zend_Log::INFO); shuffle($sources); $success = 0; $failure = 0; $total = count($sources); foreach ($sources as $source) { if ($source['service'] == 'stuffpress') { continue; }
private function getAvailableSources() { $sourcesTable = new Sources(); $sources = $sourcesTable->getSources(); $s = array(); if ($sources) { foreach ($sources as $source) { $model = SourceModel::newInstance($source['service']); $model->setSource($source); if ($model->isStoryElement()) { $s[$source['id']] = $model->getServiceName() . "(" . $model->getAccountName() . ")"; } } } return $s; }
private function getAvailableSources() { $sourcesTable = new Sources(); $sources = $sourcesTable->getSources(); $s = array(); if ($sources) { foreach ($sources as $source) { $model = SourceModel::newInstance($source['service'], $source); $account = $model->getAccountName() ? "(" . $model->getAccountName() . ")" : ""; $s[$source['id']] = $model->getServiceName() . $account; } } return $s; }
private function validateSources($string) { $sources_db = new Sources(); $sources_u = $sources_db->getSources(); $result = array(); $i_sources = explode(",", $string); foreach ($i_sources as $s) { if (!isset($sources_u[$s])) { return false; } $result[] = $s; } return $result; }
// Fetch the user $udb = new Users(); if (!($user = $udb->getUser($user_id))) { die("No such user with id {$user_id}"); } // Ask for confirmation fwrite(STDOUT, "Are you sure to delete user {$user->username} ({$user->email}) ? Type 'yes': "); $answer = trim(fgets(STDIN)); if ($answer != 'yes') { die("Operation aborted, nothing was deleted.\r\n"); } // Assign the shard for the database Zend_Registry::set("shard", $user->id); // Fetch all sources and delete them $sdb = new Sources(); $sources = $sdb->getSources(); // Delete all sources and associated items if ($sources && count($sources) > 0) { foreach ($sources as $source) { // Instantiate a model and remove all the data $model = SourceModel::newInstance($source['service']); $model->setSource($source); $model->deleteItems(); // Delete the duplicated from the Data table $data = new Data(); $data->deleteItems($source['id']); // Delete the source settings $properties = new SourcesProperties(array(Properties::KEY => $source['id'])); $properties->deleteAllProperties(); // Remove the source $sdb->deleteSource($source['id']);
protected function getModels() { $sources = new Sources(); $s = $sources->getSources(); $models = array(); if ($s) { foreach ($s as $source) { $model = SourceModel::newInstance($source['service'], $source); $models[$source['id']] = $model; } } return $models; }