0

I want do give the function to 'restore' deleted Object in my FE-Ext. It seems, that it does not find any deleted records an so i cannot update them set deleted = 0.

What you be you sugestion to handle that from the controller?:

$query->getQuerySettings()->setIgnoreEnableFields(TRUE);
$query->getQuerySettings()->setIncludeDeleted(TRUE);

Thank you.

metaxos
  • 151
  • 1
  • 16

3 Answers3

1

Im not quite sure what you mean by "from the controller". Normally you implement this in your repository and just call the method from the controller.

In your repo:

public function findRecordEvenIfItIsDeleted($uid) {
    $query = $this->createQuery();
    $settings = $query->getQuerySettings();
    settings->setIgnoreEnableFields(TRUE);
    settings->setIncludeDeleted(TRUE);
    $query->matching($query->equals('uid', $uid));
    return $query->execute();
}

In your controller:

$myObject = $this->myRepsository->findRecordEvenIfItIsDeleted($uid);

Done. (Of course your storage pid must be set (or disable respectStoragePage as well)

Daniel
  • 6,916
  • 2
  • 36
  • 47
  • Getting the records is working, i have exact the method you have in the repository. But when i want to update such a record (kind of restore record) and therefore set deleted = 0 whithin my method in the controller (ex. recoverRecordAction) then the record seems to be invisible to the chontroller Action (because it is still deleted = 0)? `code` Exception while property mapping at property path "":Object with identity "4" not found – metaxos Feb 10 '14 at 21:20
0

You're adding does not throw any error because you are setting the querySettings to include deleted records. But maybe, this setting has to be enabled even when you are updating, as the repository should find the object you are updating. I haven't tested it but give this a try.

In your repository(just a pseudo code)

public function update($modifiedObject) {
    settings->setIncludeDeleted(TRUE);
    parent::update($modifiedObject);
}
dora
  • 1,314
  • 2
  • 22
  • 38
0

I know this question was asked long time ago but today i had a similar problem with a hidden object. My solution was this one:

add this to your Model (in your case exchange "hidden" by "deleted"):

/**
 * @var boolean
 */
protected $hidden;


/**
 * @return boolean $hidden
 */
public function getHidden() {
    return $this->hidden;
}

/**
 * @return boolean $hidden
 */
public function isHidden() {
    return $this->getHidden();
}

/**
 * @param boolean $hidden
 * @return void
 */
public function setHidden($hidden) {
    $this->hidden = $hidden;
}

in your repository add this function to find the deleted/hidden object:

public function findHiddenByUid($uid) {
    $query = $this->createQuery();
    $query->getQuerySettings()->setIgnoreEnableFields(TRUE);
    $query->getQuerySettings()->setEnableFieldsToBeIgnored(array('disabled','hidden'));
    return $query
    ->matching($query->equals('uid', $uid))
    ->execute()
    ->getFirst();
}

now in your Controller you can read the object, set the "hidden" option and update it:

$yourobject = $this->yourobjectRepository->findHiddenByUid($uid);
$yourobject->setHidden(1);
$this->yourobjectRepository->update($yourobject);

Maybe not interesting for your task but for others: In my case i additionally had the problem posting a hidden object in a form to an action. So note that if you want to post an object by a form, it is better (or probably necessary) to first set the objects deleted/hidden option to 0.

uldo
  • 166
  • 1
  • 5