1

I have created an extension and i would like to import and remove data on my ImportAction. Although the Import snippet works, the remove does not.

Note that this did not work for me.

Here is what i have so far:

  1. I installed my extension on my TYPO3 installation
  2. I have the static template included
  3. I have included the PID on the constant editor
  4. I cleared everything that has to do with cache
  5. I created 2 elements on the database and the pid=4 is there. That means that the constant editor setting works.

I am using TYPO3 7.6.23

Here is my code that does not work:

$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$myRepository = $objectManager->get('BW....\MyImporter\Domain\Repository\MyRepository');
$myRepository->removeAll();

Here is the code that imports data successfully (Here i am using USE on the top of my PHP file that is the reason why there is this myImport::class).

 $finalTitle = 'This is a Test';
 $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
 $newMyImport = $objectManager->get(myImport::class);
 $newMyImport->setTitle($finalTitle);
 $this->myRepository->add($newMyImport);
 print_r($newMyImport);

How can i remove all the elements from my database ALONG WITH the IDs? It will not be nice if the ID reaches the 254206782.

Thanks in advance,

Aristeidis Karavas
  • 1,891
  • 10
  • 29
  • You have to set PID over Typosscript or use a Queryset, see answers here https://stackoverflow.com/questions/44539156/typo3-repository-findall-not-working. This does set deleted=1, not remove the entry completly like TRUNCATE, as you did in your solution. – Martin Krung Jun 15 '18 at 09:59

3 Answers3

0

The uid field is AUTO_INCREMENT, which only gets reset when you drop+recreate the table.

So even after deleting the the row with the highest uid of 100, the next new row will get 101 as uid.

cweiske
  • 30,033
  • 14
  • 133
  • 194
0

You can do with some naked SQL. Also you can use some tools like phpMyAdmin, Adminer or Sequel if they support this actions in the GUI.

As TYPO3 does not delete any records but marks them deleted you first needs to realy remove the deleted records.

DELETE * FROM <table> WHERE deleted = 1;

Then you need to evaluate a new autoincrement value, which could be:

SELECT max(uid) from <table>;

Add 1 to the result.

As this still could be a very high value (e.g. if the last record was not deleted) you might use a lower value and the next free id will be used.

And now you could set the autoincrement to your value:

ALTER TABLE <table> AUTO_INCREMENT=<your value>; 
Bernd Wilke πφ
  • 10,390
  • 1
  • 19
  • 38
  • This is insufficient, it's possible to have e.g. a page with deleted=1 and subpages with deleted=0, however they're not referenced anywhere and should thus be deleted as well. – pcworld May 29 '20 at 17:02
0

A little bit late but i figured a way to do it and it works perfectly.

I had to truncate my table!

This is the code on my Task.php (because i had it on my scheduler).

/*Create connection to Truncate the database*/
    $servername = TYPO3_db_host;
    $username = TYPO3_db_username;
    $password = TYPO3_db_password;
    $dbname = TYPO3_db;
    // Create connection
    $databaseConnect = mysqli_connect($servername, $username, $password, $dbname);
    $repositoryRemove = "TRUNCATE TABLE tx_importer_domain_model_import";
    $repositoryAttachmentsRemove = "TRUNCATE TABLE tx_importer_domain_model_attachments";
    $mysql = mysqli_query($databaseConnect, $repositoryRemove);
    $mysql1 = mysqli_query($databaseConnect, $repositoryAttachmentsRemove);
    mysqli_close($databaseConnect);

And simply as that, the deletion of my Tables was a success!

Best regards,

Aristeidis Karavas
  • 1,891
  • 10
  • 29