Ejemplo n.º 1
0
 /**
  * Get tables for menu example
  *
  * @param int $startUid UID from selected page
  * @param int $depth How many levels recursive
  * @return string The tables to be displayed
  */
 public function getTables($startUid, $depth = 0)
 {
     $deletedRecordsTotal = 0;
     $lang = $this->getLanguageService();
     $tables = array();
     foreach (RecyclerUtility::getModifyableTables() as $tableName) {
         $deletedField = RecyclerUtility::getDeletedField($tableName);
         if ($deletedField) {
             // Determine whether the table has deleted records:
             $deletedCount = $this->getDatabaseConnection()->exec_SELECTcountRows('uid', $tableName, $deletedField . '<>0');
             if ($deletedCount) {
                 /* @var $deletedDataObject \TYPO3\CMS\Recycler\Domain\Model\DeletedRecords */
                 $deletedDataObject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Recycler\Domain\Model\DeletedRecords::class);
                 $deletedData = $deletedDataObject->loadData($startUid, $tableName, $depth)->getDeletedRows();
                 if (isset($deletedData[$tableName])) {
                     if ($deletedRecordsInTable = count($deletedData[$tableName])) {
                         $deletedRecordsTotal += $deletedRecordsInTable;
                         $tables[] = array($tableName, $deletedRecordsInTable, RecyclerUtility::getUtf8String($lang->sL($GLOBALS['TCA'][$tableName]['ctrl']['title'])));
                     }
                 }
             }
         }
     }
     $jsonArray = $tables;
     array_unshift($jsonArray, array('', $deletedRecordsTotal, $lang->sL('LLL:EXT:recycler/mod1/locallang.xlf:label_allrecordtypes')));
     return $jsonArray;
 }
Ejemplo n.º 2
0
 /**
  * Get tables for menu example
  *
  * @param 	string		$format: Return format (example: json)
  * @param 	boolean		$withAllOption: 0 no, 1 return tables with a "all" option
  * @param 	integer		$id: UID from selected page
  * @param 	integer		$depth: How many levels recursive
  * @return 	string		The tables to be displayed
  */
 public function getTables($format, $withAllOption = 0, $startUid, $depth = 0)
 {
     $deletedRecordsTotal = 0;
     $tables = array();
     foreach (array_keys($GLOBALS['TCA']) as $tableName) {
         $deletedField = \TYPO3\CMS\Recycler\Utility\RecyclerUtility::getDeletedField($tableName);
         if ($deletedField) {
             // Determine whether the table has deleted records:
             $deletedCount = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid', $tableName, $deletedField . '<>0');
             if ($deletedCount) {
                 $deletedDataObject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Recycler\\Domain\\Model\\DeletedRecords');
                 $deletedData = $deletedDataObject->loadData($startUid, $tableName, $depth)->getDeletedRows();
                 if (isset($deletedData[$tableName])) {
                     if ($deletedRecordsInTable = count($deletedData[$tableName])) {
                         $deletedRecordsTotal += $deletedRecordsInTable;
                         $tables[] = array($tableName, $deletedRecordsInTable, $tableName, \TYPO3\CMS\Recycler\Utility\RecyclerUtility::getUtf8String($GLOBALS['LANG']->sL($GLOBALS['TCA'][$tableName]['ctrl']['title'])));
                     }
                 }
             }
         }
     }
     $jsonArray = $tables;
     if ($withAllOption) {
         array_unshift($jsonArray, array('', $deletedRecordsTotal, '', $GLOBALS['LANG']->sL('LLL:EXT:recycler/mod1/locallang.xlf:label_alltables')));
     }
     $output = json_encode($jsonArray);
     return $output;
 }
Ejemplo n.º 3
0
 /**
  * Get tables for menu example
  *
  * @param int $startUid UID from selected page
  * @param int $depth How many levels recursive
  * @return string The tables to be displayed
  */
 public function getTables($startUid, $depth = 0)
 {
     $deletedRecordsTotal = 0;
     $lang = $this->getLanguageService();
     $tables = array();
     $connection = GeneralUtility::makeInstance(ConnectionPool::class);
     foreach (RecyclerUtility::getModifyableTables() as $tableName) {
         $deletedField = RecyclerUtility::getDeletedField($tableName);
         if ($deletedField) {
             // Determine whether the table has deleted records:
             $queryBuilder = $connection->getQueryBuilderForTable($tableName);
             $queryBuilder->getQueryContext()->setContext(QueryContextType::UNRESTRICTED);
             $deletedCount = $queryBuilder->count('uid')->from($tableName)->where($queryBuilder->expr()->neq($deletedField, 0))->execute()->fetchColumn();
             if ($deletedCount) {
                 /* @var $deletedDataObject DeletedRecords */
                 $deletedDataObject = GeneralUtility::makeInstance(DeletedRecords::class);
                 $deletedData = $deletedDataObject->loadData($startUid, $tableName, $depth)->getDeletedRows();
                 if (isset($deletedData[$tableName])) {
                     if ($deletedRecordsInTable = count($deletedData[$tableName])) {
                         $deletedRecordsTotal += $deletedRecordsInTable;
                         $tables[] = array($tableName, $deletedRecordsInTable, $lang->sL($GLOBALS['TCA'][$tableName]['ctrl']['title']));
                     }
                 }
             }
         }
     }
     $jsonArray = $tables;
     array_unshift($jsonArray, array('', $deletedRecordsTotal, $lang->sL('LLL:EXT:recycler/mod1/locallang.xlf:label_allrecordtypes')));
     return $jsonArray;
 }
 /**
  * Transforms the rows for the deleted Records into the Array View necessary for ExtJS Ext.data.ArrayReader
  *
  * @param array     $rows   Array with table as key and array with all deleted rows
  * @param integer	$totalDeleted: Number of deleted records in total, for PagingToolbar
  * @return string   JSON Array
  */
 public function transform($deletedRowsArray, $totalDeleted)
 {
     $total = 0;
     $jsonArray = array('rows' => array());
     // iterate
     if (is_array($deletedRowsArray) && count($deletedRowsArray) > 0) {
         foreach ($deletedRowsArray as $table => $rows) {
             $total += count($deletedRowsArray[$table]);
             foreach ($rows as $row) {
                 $backendUser = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('be_users', $row[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']], 'username', '', FALSE);
                 $jsonArray['rows'][] = array('uid' => $row['uid'], 'pid' => $row['pid'], 'table' => $table, 'crdate' => \TYPO3\CMS\Backend\Utility\BackendUtility::datetime($row[$GLOBALS['TCA'][$table]['ctrl']['crdate']]), 'tstamp' => \TYPO3\CMS\Backend\Utility\BackendUtility::datetime($row[$GLOBALS['TCA'][$table]['ctrl']['tstamp']]), 'owner' => htmlspecialchars($backendUser['username']), 'owner_uid' => $row[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']], 'tableTitle' => \TYPO3\CMS\Recycler\Utility\RecyclerUtility::getUtf8String($GLOBALS['LANG']->sL($GLOBALS['TCA'][$table]['ctrl']['title'])), 'title' => htmlspecialchars(\TYPO3\CMS\Recycler\Utility\RecyclerUtility::getUtf8String(\TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle($table, $row))), 'path' => \TYPO3\CMS\Recycler\Utility\RecyclerUtility::getRecordPath($row['pid']));
             }
         }
     }
     $jsonArray['total'] = $totalDeleted;
     return json_encode($jsonArray);
 }
 /**
  * Transforms the rows for the deleted records
  *
  * @param array $deletedRowsArray Array with table as key and array with all deleted rows
  * @param int $totalDeleted Number of deleted records in total
  * @return string JSON array
  */
 public function transform($deletedRowsArray, $totalDeleted)
 {
     $total = 0;
     $jsonArray = array('rows' => array());
     if (is_array($deletedRowsArray)) {
         $lang = $this->getLanguageService();
         $backendUser = $this->getBackendUser();
         foreach ($deletedRowsArray as $table => $rows) {
             $total += count($deletedRowsArray[$table]);
             foreach ($rows as $row) {
                 $pageTitle = $this->getPageTitle((int) $row['pid']);
                 $backendUser = BackendUtility::getRecord('be_users', $row[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']], 'username', '', FALSE);
                 $jsonArray['rows'][] = array('uid' => $row['uid'], 'pid' => $row['pid'], 'icon' => IconUtility::getSpriteIconForRecord($table, $row), 'pageTitle' => RecyclerUtility::getUtf8String($pageTitle), 'table' => $table, 'crdate' => BackendUtility::datetime($row[$GLOBALS['TCA'][$table]['ctrl']['crdate']]), 'tstamp' => BackendUtility::datetime($row[$GLOBALS['TCA'][$table]['ctrl']['tstamp']]), 'owner' => htmlspecialchars($backendUser['username']), 'owner_uid' => $row[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']], 'tableTitle' => RecyclerUtility::getUtf8String($lang->sL($GLOBALS['TCA'][$table]['ctrl']['title'])), 'title' => htmlspecialchars(RecyclerUtility::getUtf8String(BackendUtility::getRecordTitle($table, $row))), 'path' => RecyclerUtility::getRecordPath($row['pid']));
             }
         }
     }
     $jsonArray['total'] = $totalDeleted;
     return $jsonArray;
 }
Ejemplo n.º 6
0
 /**
  * Transforms the rows for the deleted records
  *
  * @param array $deletedRowsArray Array with table as key and array with all deleted rows
  * @param int $totalDeleted Number of deleted records in total
  * @return string JSON array
  */
 public function transform($deletedRowsArray, $totalDeleted)
 {
     $total = 0;
     $jsonArray = array('rows' => array());
     if (is_array($deletedRowsArray)) {
         $lang = $this->getLanguageService();
         $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
         foreach ($deletedRowsArray as $table => $rows) {
             $total += count($deletedRowsArray[$table]);
             foreach ($rows as $row) {
                 $pageTitle = $this->getPageTitle((int) $row['pid']);
                 $backendUser = BackendUtility::getRecord('be_users', $row[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']], 'username', '', false);
                 $jsonArray['rows'][] = array('uid' => $row['uid'], 'pid' => $row['pid'], 'icon' => $iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render(), 'pageTitle' => $pageTitle, 'table' => $table, 'crdate' => BackendUtility::datetime($row[$GLOBALS['TCA'][$table]['ctrl']['crdate']]), 'tstamp' => BackendUtility::datetime($row[$GLOBALS['TCA'][$table]['ctrl']['tstamp']]), 'owner' => htmlspecialchars($backendUser['username']), 'owner_uid' => $row[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']], 'tableTitle' => $lang->sL($GLOBALS['TCA'][$table]['ctrl']['title']), 'title' => htmlspecialchars(BackendUtility::getRecordTitle($table, $row)), 'path' => RecyclerUtility::getRecordPath($row['pid']));
             }
         }
     }
     $jsonArray['total'] = $totalDeleted;
     return $jsonArray;
 }
Ejemplo n.º 7
0
 /**
  * Checks whether the current backend user has access to the given records.
  *
  * @param 	string		$table: Name of the table
  * @param 	array		$rows: Record row
  * @return 	void
  */
 protected function checkRecordAccess($table, array $rows)
 {
     foreach ($rows as $key => $row) {
         if (\TYPO3\CMS\Recycler\Utility\RecyclerUtility::checkAccess($table, $row)) {
             $this->setDeletedRows($table, $row);
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Undelete records
  * If $recursive is TRUE all records below the page uid would be undelete too
  *
  * @param array $recordsArray Representation of the records
  * @param bool $recursive Whether to recursively undelete
  * @return bool|int
  */
 public function undeleteData($recordsArray, $recursive = false)
 {
     $result = false;
     $affectedRecords = 0;
     $depth = 999;
     if (is_array($recordsArray)) {
         $this->deletedRows = array();
         $cmd = array();
         foreach ($recordsArray as $record) {
             list($table, $uid) = explode(':', $record);
             // get all parent pages and cover them
             $pid = RecyclerUtility::getPidOfUid($uid, $table);
             if ($pid > 0) {
                 $parentUidsToRecover = $this->getDeletedParentPages($pid);
                 $count = count($parentUidsToRecover);
                 for ($i = 0; $i < $count; ++$i) {
                     $parentUid = $parentUidsToRecover[$i];
                     $cmd['pages'][$parentUid]['undelete'] = 1;
                     $affectedRecords++;
                 }
                 if (isset($cmd['pages'])) {
                     // reverse the page list to recover it from top to bottom
                     $cmd['pages'] = array_reverse($cmd['pages'], TRUE);
                 }
             }
             $cmd[$table][$uid]['undelete'] = 1;
             $affectedRecords++;
             if ($table === 'pages' && $recursive) {
                 $this->loadData($uid, '', $depth, '');
                 $childRecords = $this->getDeletedRows();
                 if (!empty($childRecords)) {
                     foreach ($childRecords as $childTable => $childRows) {
                         foreach ($childRows as $childRow) {
                             $cmd[$childTable][$childRow['uid']]['undelete'] = 1;
                         }
                     }
                 }
             }
         }
         if ($cmd) {
             $tce = GeneralUtility::makeInstance(DataHandler::class);
             $tce->start(array(), $cmd);
             $tce->process_cmdmap();
             $result = $affectedRecords;
         }
     }
     return $result;
 }