public function start($url, $host = null, $reset = false) { if (empty($url)) { return; } if (array_key_exists('HTTP_HOST', $_SERVER)) { $this->_host = $_SERVER['HTTP_HOST']; } else { if ($host !== null) { $this->_host = $host; } else { throw new Zend_Exception('No host set for Spider'); } } Bbx_Log::write('Starting Spider with url ' . $url, null, Bbx_Search::LOG); $this->_report = Bbx_Model::load('SearchIndexReport')->create(); $this->_report->start(); if ($reset) { Bbx_Log::write('Resetting search index', null, Bbx_Search::LOG); $this->_search()->reset(); } $this->_spider($url); Bbx_Log::write('Optimizing index', null, Bbx_Search::LOG); $this->_search()->optimize(); Bbx_Log::write('Completing index', null, Bbx_Search::LOG); $this->_report->complete($this->_indexed); Bbx_Log::write('Spider done', null, Bbx_Search::LOG); }
public static function getExternalConditions($select, $parentModel, $childName, $attributes) { $parentModelName = get_class($parentModel); $parentTableName = $parentModel->getTableName(); // exhibitions $childName = array_key_exists('source', $attributes) ? $attributes['source'] : $childName; $childModelName = Inflector::classify($childName); $childTableName = Bbx_Model::load($childModelName)->getTableName(); // images if (!array_key_exists($childTableName, $select->getPart('from'))) { $select->from($childTableName, array()); // images } if (array_key_exists('as', $attributes)) { $refColumn = $attributes['as'] . '_id'; $polyType = $attributes['as'] . '_type'; } else { $refColumn = Inflector::singularize($parentTableName) . '_id'; } try { $parentModel->getRowData(); $select->where("`" . $childTableName . "`.`" . $refColumn . "` = " . $parentModel->id); } catch (Exception $e) { $select->where("`" . $childTableName . "`.`" . $refColumn . "` = `" . $parentTableName . "`.`id`"); } if (isset($polyType)) { $select->where("`" . $childTableName . "`.`" . $polyType . "` = '" . Inflector::underscore($parentModelName) . "'"); } return $select; }
protected function _getMostRecentReport() { $all = Bbx_Model::load('SearchIndexReport')->findAll(); if (count($all) > 0) { return $all->first(); } return false; }
public function hasPrivilege($roleName) { $role = Bbx_Model::load('Role')->find(array('name' => $roleName)); if (!$role instanceof Bbx_Model_Default_Role || !$this->role instanceof Bbx_Model_Default_Role) { return false; } return (int) $this->role->precedence <= (int) $role->precedence; }
public function delete() { try { $this->deleteMedia(); } catch (Exception $e) { Bbx_Log::debug('Unable to delete media ' . get_class($this) . ' id ' . $this->id . ' - ' . $e->getMessage()); } parent::delete(); }
protected function _model($childModelName = null) { $childModelName = $childModelName ? $childModelName : $this->_childModelName; $this->_childModelName = $childModelName; if (!isset($this->_models[$childModelName])) { $this->_models[$childModelName] = Bbx_Model::load($childModelName); } return $this->_models[$childModelName]; }
protected function _instantiateRowModel($row) { if ($row instanceof Bbx_Model) { $model = $row; } else { $model = Bbx_Model::load($this->getModelName()); $model->setRowData($row); } return $this->_renderAsList ? array('id' => $model->id, 'label' => $model->__toString()) : $model; }
public function resolve($username, $realm) { $users = Bbx_Model::load('User'); $user = $users->find($users->select()->where('username = ?', $username)); if (!$user instanceof Bbx_Model) { return null; } $this->_user = $user; return $user->password; }
protected function _doSearchIndex() { try { $report = Bbx_Model::load('SearchIndexReport'); $time = $report->timeSinceLastIndex(); Bbx_Log::write('Last search-index was ' . $time . 's ago'); if ($time > 86400) { Bbx_Log::write('> 24h elapsed, running index'); $pid = exec('nice php ' . APPLICATION_PATH . '/../library/Bbx/bin/search-index.php ' . $_SERVER['HTTP_HOST'] . ' > /dev/null 2>&1 &'); } } catch (Exception $e) { Bbx_Log::write('Unable to do search index: ' . $e->getMessage()); } }
public function getCollection() { $request = $this->getRequest(); $controllerName = $request->getControllerName(); if ($controllerName == 'error') { return; } $params = $this->parseParams($request->getParams()); $collection = Bbx_Model::load($controllerName); if (($id = $request->getParam('id')) && ($rel = $request->getParam('rel'))) { $collection = $collection->find((int) $id)->{$rel}; if ($collection instanceof Bbx_Model) { return $collection; } } $collection = $collection->findAll($params); return $collection; }
public static function getExternalConditions($select, $parentModel, $childName, $attributes) { $parentModelName = get_class($parentModel); $parentTableName = $parentModel->getTableName(); $childName = array_key_exists('source', $attributes) ? attributes('source') : $childName; $childModelName = Inflector::classify($childName); $childTableName = Bbx_Model::load($childModelName)->getTableName(); $refColumn = Inflector::singularize($childTableName) . '_id'; if (!array_key_exists($childTableName, $select->getPart('from'))) { $select->from($childTableName, array()); } if (!array_key_exists($parentTableName, $select->getPart('from'))) { $select->from($parentTableName, array()); } $select->where("`" . $parentTableName . "`.`" . $refColumn . "` = `" . $childTableName . "`.`id`"); try { $parentModel->getRowData(); $select->where("`" . $parentTableName . "`.`id` = " . $parentModel->id); } catch (Exception $e) { } return $select; }
public static function getExternalConditions($select, $parentModel, $childName, $attributes) { $parentModelName = get_class($parentModel); $parentTableName = $parentModel->getTableName(); $childName = array_key_exists('source', $attributes) ? attributes('source') : $childName; $childModelName = Inflector::classify($childName); $childModel = Bbx_Model::load($childModelName); $childTableName = $childModel->getTableName(); $childColumns = $childModel->columns(); $throughName = $attributes['through']; $throughModelName = Inflector::classify($throughName); $throughModel = Bbx_Model::load($throughModelName); $throughTableName = $throughModel->getTableName(); $throughColumns = $throughModel->columns(); if (!array_key_exists($childTableName, $select->getPart('from'))) { $select->from($childTableName, array()); } if (array_key_exists('as', $attributes)) { $refColumn = $attributes['as'] . '_id'; $polyType = $attributes['as'] . '_type'; } else { $refColumn = Inflector::singularize($parentTableName) . '_id'; } $childKey = Inflector::singularize($childTableName) . '_id'; $throughKey = Inflector::singularize($throughTableName) . '_id'; $select->from($throughTableName, array())->where("`" . $throughTableName . "`.`" . $refColumn . "` = " . $parentModel->id); if (in_array($childKey, $throughColumns)) { $select->where("`" . $throughTableName . "`.`" . $childKey . "` = `" . $childTableName . "`.id"); } else { if (in_array($throughKey, $childColumns)) { $select->where("`" . $childTableName . "`.`" . $throughKey . "` = `" . $throughTableName . "`.id"); } } if (array_key_exists('as', $attributes)) { $select->where("`" . $throughTableName . "`.`" . $polyType . "` = '" . Inflector::singularize($parentTableName) . "'"); } return $select; }
public function handleUpload($collection) { $request = $this->getRequest(); $response = $this->getResponse(); if ($request->getHeader("Content-Length") == 0) { $response->setHttpResponseCode(204)->sendResponse(); exit; } $mimeType = Bbx_Model::load($collection->getModelName())->getMimeType(); $max_size = ini_get('upload_max_filesize'); $post_max = ini_get('post_max_size'); if ($post_max < $max_size) { $max_size = $post_max; } $upload = new Zend_File_Transfer_Adapter_Http(); // TODO throws error 'Magicfile can not be set. There is no finfo extension installed' (Zend_Validate_File_MimeType 193) // $upload->addValidator('MimeType', false, $mimeType); $upload->getValidator('Zend_Validate_File_Upload')->setMessage('File is too large - max size ' . $max_size, Zend_Validate_File_Upload::INI_SIZE); if ($upload->receive()) { Bbx_Log::debug("upload received"); $files = $upload->getFileInfo(); $media = $files['file_data']; Bbx_Log::debug(print_r($media, true)); $new_model = $collection->create(); try { $new_model->attachMedia($media['tmp_name']); $new_model->save(); } catch (Exception $e) { $new_model->delete(); throw $e; } return $new_model; } else { $this->_throwUploadException($upload); } }
protected static function _encodeHeader(Bbx_Model $model) { $a = $model->columns(); foreach ($a as $key => $val) { if (@strpos($val, '_id', strlen($val) - 3) !== false) { $val = substr($val, 0, -3); $a[$key] = $val; } } $model = null; return self::_encodeArrayRow($a); }
protected function _post() { $this->_helper->authenticate(); $collection = $this->_helper->Model->getCollection(); if ($collection instanceof Bbx_Model) { // It's a hasOne-type model throw new Bbx_Controller_Rest_Exception(null, 405, array('allowed_methods' => 'GET,PUT')); } $model = Bbx_Model::load($collection->getModelName()); if ($model instanceof Bbx_Model_Default_Media) { $new_model = $this->_helper->Media->handleUpload($collection); } else { $new_model = $collection->create($this->_getBodyData()); } Bbx_CacheManager::clean($this->getRequest(), 'post'); $this->getResponse()->setHttpResponseCode(201)->setHeader('Location', $new_model->url(true))->setBody(Zend_Json::encode($new_model->toArray()))->sendResponse(); //TODO if we exit, we can't use postDispatch hooks ... also, this presumes we always want to respond with JSON exit; }
public function updateAllAction() { $this->_helper->authenticate(); $model = $this->_getParam('model'); try { $models = Bbx_Model::load($model)->findAll(); foreach ($models as $m) { $m->update(array()); } } catch (Exception $e) { Bbx_Log::debug($e->getMessage()); } $this->getResponse()->sendResponse(); exit; }
public function __construct(Bbx_Model $model) { $this->_model = $model; $this->_cols = $model->columns(); }