Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index all addon records, and allow public addons to the public. #140

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 9 additions & 49 deletions lib/SolrSearch/Addon/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ public function indexRecord($record, $addon)
$doc->addField('modelid', $record->id);

// extend $doc to include public / private records
// not sure if required
//$doc->addField('public', $record->public);
$doc->addField('public', $this->isRecordPublic($record, $addon));

$titleField = $addon->getTitleField();
foreach ($addon->fields as $field) {
Expand Down Expand Up @@ -236,77 +235,38 @@ public function buildSelect($table, $addon)
->select()
->from($table->getTableName());

if ($addon->hasFlag()) {
$this->_addFlag($select, $addon);
}

return $select;
}


/**
* This adds the joins and where clauses to respect an addon's privacy
* settings.
*
* @param Omeka_Db_Select $select The select object to modify.
* @param SolrSearch_Addon_Addon $addon The current addon. You should
* already know that this addon does have a public flag somewhere in its
* hierarchy before calling this.
*
* @return null
* @author Eric Rochester <[email protected]>
**/
private function _addFlag($select, $addon)
{
if (!is_null($addon->flag)) {
$table = $this->db->getTable($addon->table);
$select->where(
"`{$table->getTableName()}`.`{$addon->flag}`=1"
);
} else if (!is_null($addon->parentAddon)) {
$parent = $addon->parentAddon;
$table = $this->db->getTable($addon->table)->getTableName();
$ptable = $this->db->getTable($parent->table)->getTableName();

$select->join(
$ptable,
"`$table`.`{$addon->parentKey}`=`$ptable`.`{$parent->idColumn}`",
array()
);

$this->_addFlag($select, $parent);
}
}


/**
* This returns true if this addon (and none of its ancestors) are flagged.
* This returns true if this addon (or one of its ancestors) are flagged.
*
* @param Omeka_Record $record The Omeka record to consider indexing.
* @param Omeka_Record $record The Omeka record to check if public.
* @param SolrSearch_Addon_Addon $addon The addon for the record.
*
* @return bool $indexed A flag indicating whether to index the record.
* @return bool $indexed A flag indicating whether the record is public.
* @author Eric Rochester <[email protected]>
**/
public function isRecordIndexed($record, $addon)
public function isRecordPublic($record, $addon)
{
$indexed = true;
$public = true;

if (is_null($record)) {

} else if (!is_null($addon->flag)) {
$flag = $addon->flag;
$indexed = $record->$flag;
$public = $record->$flag;

} else if (!is_null($addon->parentAddon)) {
$key = $addon->parentKey;
$table = $this->db->getTable($addon->parentAddon->table);
$parent = $table->find($record->$key);

$indexed = $this->isRecordIndexed($parent, $addon->parentAddon);
$public = $this->isRecordPublic($parent, $addon->parentAddon);
}

return $indexed;
return $public;
}


Expand Down
2 changes: 1 addition & 1 deletion lib/SolrSearch/Addon/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function indexRecord($record, $config=null)
}

$addon = $this->findAddonForRecord($record);
if (!is_null($addon) && $idxr->isRecordIndexed($record, $addon)) {
if (!is_null($addon)) {
$doc = $idxr->indexRecord($record, $addon);
}

Expand Down