예제 #1
0
 /**
  * Returns the users which are in the groups with the given UIDs.
  *
  * @param string $groupUids
  *        the UIDs of the user groups from which to get the users, must be a
  *        comma-separated list of group UIDs, must not be empty
  *
  * @return Tx_Oelib_List<Tx_Oelib_Model_FrontEndUser> the found user models, will be empty if
  *                       no users were found for the given groups
  */
 public function getGroupMembers($groupUids)
 {
     if ($groupUids === '') {
         throw new InvalidArgumentException('$groupUids must not be an empty string.', 1331488505);
     }
     return $this->getListOfModels(Tx_Oelib_Db::selectMultiple('*', $this->getTableName(), $this->getUniversalWhereClause() . ' AND ' . 'usergroup REGEXP \'(^|,)(' . implode('|', t3lib_div::intExplode(',', $groupUids)) . ')($|,)\''));
 }
예제 #2
0
 /**
  * Returns the number of records matching the given WHERE clause.
  *
  * @param string $whereClause
  *        WHERE clause for the number of records to retrieve, must be quoted
  *        and SQL safe, may be empty
  *
  * @return int the number of records matching the given WHERE clause
  */
 public function countByWhereClause($whereClause = '')
 {
     $completeWhereClause = $whereClause === '' ? '' : $whereClause . ' AND ';
     return Tx_Oelib_Db::count($this->getTableName(), $completeWhereClause . $this->getUniversalWhereClause());
 }
예제 #3
0
파일: Db.php 프로젝트: Konafets/oelib
 /**
  * Retrieves the table names of the current DB and stores them in
  * self::$tableNameCache.
  *
  * This function does nothing if the table names already have been
  * retrieved.
  *
  * @return void
  */
 private static function retrieveTableNames()
 {
     if (!empty(self::$tableNameCache)) {
         return;
     }
     self::$tableNameCache = self::getDatabaseConnection()->admin_get_tables();
 }
예제 #4
0
 /**
  * @test
  */
 public function messageAfterQueryWithLastQueryEnabledContainsLastQuery()
 {
     Tx_Oelib_Db::getDatabaseConnection()->exec_SELECTquery('title', 'tx_oelib_test', '');
     $subject = new tx_oelib_Exception_EmptyQueryResult();
     self::assertContains('SELECT', $subject->getMessage());
 }
예제 #5
0
 /**
  * Frees as much memory that has been used by this object as possible.
  */
 public function __destruct()
 {
     $databaseConnection = Tx_Oelib_Db::getDatabaseConnection();
     if ($this->dbResult !== FALSE && $databaseConnection !== NULL) {
         $databaseConnection->sql_free_result($this->dbResult);
         $this->dbResult = FALSE;
     }
     $this->currentItem = NULL;
 }
예제 #6
0
 /**
  * @test
  */
 public function saveCanSaveFloatDataToStringColumn()
 {
     $model = new Tx_Oelib_Tests_Unit_Fixtures_TestingModel();
     $model->setData(array('string_data' => 9.5));
     $this->subject->save($model);
     self::assertSame(array('string_data' => '9.5'), Tx_Oelib_Db::selectSingle('string_data', 'tx_oelib_test', 'uid = ' . $model->getUid()));
 }
예제 #7
0
파일: DbTest.php 프로젝트: Konafets/oelib
 /**
  * @test
  */
 public function getDatabaseConnectionReturnsGlobalsDatabaseConnection()
 {
     self::assertSame($GLOBALS['TYPO3_DB'], Tx_Oelib_Db::getDatabaseConnection());
 }
예제 #8
0
 /**
  * Checks whether a configuration value either is empty or contains a
  * comma-separated list of PIDs that specify pages or a given type.
  *
  * @param string $fieldName
  *        TS setup field name to extract, must not be empty
  * @param bool $canUseFlexforms
  *        whether the value can also be set via flexforms (this will be
  *        mentioned in the error message)
  * @param string $sheet
  *        flexforms sheet pointer, eg. "sDEF", will be ignored if
  *        $canUseFlexforms is set to FALSE
  * @param string $explanation
  *        a sentence explaining what that configuration value is needed for,
  *        must not be empty
  * @param string $typeCondition
  *        a comparison operator with a value that will be used in a SQL
  *        query to check for the correct page types, for example "<199" or
  *        "=254", must not be empty
  *
  * @return void
  */
 protected function checkPageTypeOrEmpty($fieldName, $canUseFlexforms, $sheet, $explanation, $typeCondition)
 {
     $this->checkIfPidListOrEmpty($fieldName, $canUseFlexforms, $sheet, $explanation);
     if ($this->objectToCheck->hasConfValueString($fieldName, $sheet)) {
         $pids = $this->objectToCheck->getConfValueString($fieldName, $sheet);
         $offendingPids = Tx_Oelib_Db::selectColumnForMultiple('uid', 'pages', 'uid IN (' . $pids . ') AND NOT (doktype' . $typeCondition . ')' . Tx_Oelib_Db::enableFields('pages'));
         $dbResultCount = count($offendingPids);
         if ($dbResultCount > 0) {
             $pageIdPlural = $dbResultCount > 1 ? 's' : '';
             $bePlural = $dbResultCount > 1 ? 'are' : 'is';
             $message = 'The TS setup variable <strong>' . $this->getTSSetupPath() . $fieldName . '</strong> contains the page ID' . $pageIdPlural . ' <strong>' . implode(',', $offendingPids) . '</strong> ' . 'which ' . $bePlural . ' of an incorrect page type. ' . $explanation . '<br />';
             $this->setErrorMessageAndRequestCorrection($fieldName, $canUseFlexforms, $message);
         }
     }
 }
예제 #9
0
 /**
  * @test
  */
 public function increaseRelationCounterIncreasesNonZeroFieldValueByOne()
 {
     $uid = $this->subject->createRecord('tx_oelib_test', array('related_records' => 41));
     $this->subject->increaseRelationCounter('tx_oelib_test', $uid, 'related_records');
     $row = Tx_Oelib_Db::selectSingle('related_records', 'tx_oelib_test', 'uid = ' . $uid);
     self::assertSame(42, (int) $row['related_records']);
 }
예제 #10
0
 /**
  * Updates an integer field of a database table by one. This is mainly needed
  * for counting up the relation counter when creating a database relation.
  *
  * The field to update must be of type integer.
  *
  * @param string $tableName name of the table, must not be empty
  * @param int $uid the UID of the record to modify, must be > 0
  * @param string $fieldName the field name of the field to modify, must not be empty
  *
  * @return void
  *
  * @throws tx_oelib_Exception_Database
  * @throws InvalidArgumentException
  * @throws BadMethodCallException
  */
 public function increaseRelationCounter($tableName, $uid, $fieldName)
 {
     if (!$this->isTableNameAllowed($tableName)) {
         throw new InvalidArgumentException('The table name "' . $tableName . '" is invalid. This means it is either empty or not in the list of allowed tables.', 1331490960);
     }
     if (!Tx_Oelib_Db::tableHasColumn($tableName, $fieldName)) {
         throw new InvalidArgumentException('The table ' . $tableName . ' has no column ' . $fieldName . '.', 1331490986);
     }
     Tx_Oelib_Db::enableQueryLogging();
     $databaseConnection = Tx_Oelib_Db::getDatabaseConnection();
     $dbResult = $databaseConnection->sql_query('UPDATE ' . $tableName . ' SET ' . $fieldName . '=' . $fieldName . '+1 WHERE uid=' . $uid);
     if ($dbResult === FALSE) {
         throw new tx_oelib_Exception_Database(1418586263);
     }
     if ($databaseConnection->sql_affected_rows() === 0) {
         throw new BadMethodCallException('The table ' . $tableName . ' does not contain a record with UID ' . $uid . '.', 1331491003);
     }
     $this->markTableAsDirty($tableName);
 }