public function testProcessStatusAndMessagesForEachRow() { Yii::app()->user->userModel = User::getByUsername('super'); $import = new Import(); $serializedData['importRulesType'] = 'ImportModelTestItem'; $import->serializedData = serialize($serializedData); $this->assertTrue($import->save()); $testTableName = $import->getTempTableName(); $this->assertTrue(ImportTestHelper::createTempTableByFileNameAndTableName('importTest.csv', $testTableName, true)); $count = ImportDatabaseUtil::getCount($testTableName); $this->assertEquals(5, $count); //Now add import results. $resultsUtil = new ImportResultsUtil($import); $rowDataResultsUtil = new ImportRowDataResultsUtil(2); $rowDataResultsUtil->setStatusToUpdated(); $rowDataResultsUtil->addMessage('the first message'); $resultsUtil->addRowDataResults($rowDataResultsUtil); $rowDataResultsUtil = new ImportRowDataResultsUtil(3); $rowDataResultsUtil->setStatusToCreated(); $rowDataResultsUtil->addMessage('the second message'); $resultsUtil->addRowDataResults($rowDataResultsUtil); $rowDataResultsUtil = new ImportRowDataResultsUtil(4); $rowDataResultsUtil->setStatusToError(); $rowDataResultsUtil->addMessage('the third message'); $resultsUtil->addRowDataResults($rowDataResultsUtil); $resultsUtil->processStatusAndMessagesForEachRow(); $sql = 'select * from ' . $testTableName . ' where id != 1'; $tempTableData = ZurmoRedBean::getAll($sql); $compareData = array(array('id' => 2, 'column_0' => 'abc', 'column_1' => '123', 'column_2' => 'a', 'status' => 1, 'serializedMessages' => serialize(array('the first message')), 'analysisStatus' => null, 'serializedAnalysisMessages' => null), array('id' => 3, 'column_0' => 'def', 'column_1' => '563', 'column_2' => 'b', 'status' => 2, 'serializedMessages' => serialize(array('the second message')), 'analysisStatus' => null, 'serializedAnalysisMessages' => null), array('id' => 4, 'column_0' => 'efg', 'column_1' => '456', 'column_2' => 'a', 'status' => 3, 'serializedMessages' => serialize(array('the third message')), 'analysisStatus' => null, 'serializedAnalysisMessages' => null), array('id' => 5, 'column_0' => 'we1s', 'column_1' => null, 'column_2' => 'b', 'status' => null, 'serializedMessages' => null, 'analysisStatus' => null, 'serializedAnalysisMessages' => null)); $this->assertEquals($compareData, $tempTableData); }
public function testRun() { $quote = DatabaseCompatibilityUtil::getQuote(); //Create 2 imports, and set one with a date over a week ago (8 days ago) for the modifiedDateTime $import = new Import(); $serializedData['importRulesType'] = 'ImportModelTestItem'; $import->serializedData = serialize($serializedData); $this->assertTrue($import->save()); ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName(), true); $modifiedDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 60 * 60 * 24 * 8); $sql = "Update item set modifieddatetime = '" . $modifiedDateTime . "' where id = " . $import->getClassId('Item'); ZurmoRedBean::exec($sql); $staleImportId = $import->id; $import2 = new Import(); $serializedData['importRulesType'] = 'ImportModelTestItem'; $import2->serializedData = serialize($serializedData); $this->assertTrue($import2->save()); ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import2->getTempTableName(), true); $this->assertEquals(2, Import::getCount()); $tableExists = ZurmoRedBean::$writer->doesTableExist($import->getTempTableName()); $this->assertTrue($tableExists); $job = new ImportCleanupJob(); $this->assertTrue($job->run()); $tableExists = ZurmoRedBean::$writer->doesTableExist($import->getTempTableName()); $this->assertFalse($tableExists); $imports = Import::getAll(); $this->assertEquals(1, count($imports)); $this->assertEquals($import2->id, $imports[0]->id); }
/** * Given a name, get the custom field data model. Attempts to retrieve from cache, if it is not available, * will attempt to retrieve from persistent storage, cache the model, and return. * @param string $name * @return CustomFieldData model * @throws NotFoundException */ public static function getByName($name, $shouldCache = true) { if (isset(self::$cachedModelsByName[$name])) { return self::$cachedModelsByName[$name]; } try { // not using default value to save cpu cycles on requests that follow the first exception. return GeneralCache::getEntry('CustomFieldData' . $name); } catch (NotFoundException $e) { assert('is_string($name)'); assert('$name != ""'); $bean = ZurmoRedBean::findOne('customfielddata', "name = :name ", array(':name' => $name)); assert('$bean === false || $bean instanceof RedBean_OODBBean'); if ($bean === false) { $customFieldData = new CustomFieldData(); $customFieldData->name = $name; $customFieldData->serializedData = serialize(array()); // An unused custom field data does not present as needing saving. $customFieldData->setNotModified(); } else { $customFieldData = self::makeModel($bean); } if ($shouldCache) { self::$cachedModelsByName[$name] = $customFieldData; GeneralCache::cacheEntry('CustomFieldData' . $name, $customFieldData); } return $customFieldData; } }
/** * Runs a query to get all the dates for meetings based on SearchAttributeData. Then the data is processed * and @returns a data array of dates and quantity. Quantity stands for how many meetings in a given date. * (non-PHPdoc) * @see CalendarDataProvider::getData() */ public function getData() { $sql = $this->makeSqlQuery(); $rows = ZurmoRedBean::getAll($sql); $data = array(); foreach ($rows as $row) { $localTimeZoneAdjustedDate = DateTimeUtil::convertDbFormattedDateTimeToLocaleFormattedDisplay($row['startdatetime'], 'medium', null); if (isset($data[$localTimeZoneAdjustedDate])) { $data[$localTimeZoneAdjustedDate]['quantity'] = $data[$localTimeZoneAdjustedDate]['quantity'] + 1; } else { $data[$localTimeZoneAdjustedDate] = array('date' => $localTimeZoneAdjustedDate, 'quantity' => 1, 'dbDate' => $row['startdatetime']); } } foreach ($data as $key => $item) { if ($item['quantity'] == 1) { $label = Zurmo::t('MeetingsModule', '{quantity} MeetingsModuleSingularLabel', array_merge(LabelUtil::getTranslationParamsForAllModules(), array('{quantity}' => $item['quantity']))); } else { $label = Zurmo::t('MeetingsModule', '{quantity} MeetingsModulePluralLabel', array_merge(LabelUtil::getTranslationParamsForAllModules(), array('{quantity}' => $item['quantity']))); } $data[$key]['label'] = $label; if ($item['quantity'] > 5) { $quantityClassSuffix = 6; } else { $quantityClassSuffix = $item['quantity']; } $data[$key]['className'] = 'calendar-events-' . $quantityClassSuffix; } return $data; }
public function testRun() { $quote = DatabaseCompatibilityUtil::getQuote(); $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME); $folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_SENT); //Create 2 sent notifications, and set one with a date over a week ago (8 days ago) for the modifiedDateTime $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('My Email Message', $super); $emailMessage->folder = $folder; $saved = $emailMessage->save(); $this->assertTrue($saved); $modifiedDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 60 * 60 * 24 * 8); $sql = "Update item set modifieddatetime = '" . $modifiedDateTime . "' where id = " . $emailMessage->getClassId('Item'); ZurmoRedBean::exec($sql); $emailMessage2 = EmailMessageTestHelper::createDraftSystemEmail('My Email Message 2', $super); $emailMessage2->folder = $folder; $saved = $emailMessage2->save(); $this->assertTrue($saved); $this->assertEquals(2, EmailMessage::getCount()); $job = new ClearSentNotificationsEmailJob(); $this->assertTrue($job->run()); $emailMessages = EmailMessage::getAll(); $this->assertEquals(1, count($emailMessages)); $this->assertEquals($emailMessage2->id, $emailMessages[0]->id); }
/** * Deletes all job logs where the modifiedDateTime was more than 1 week ago. * Runs operation in bulk to improve performance when large jobLogs are present. * * @see BaseJob::run() */ public function run() { $oneWeekAgoTimeStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 60 * 60 * 24 * 7); $sql = 'DELETE from item, joblog using joblog inner join item on ' . 'item.id = joblog.item_id where joblog.enddatetime <= "' . $oneWeekAgoTimeStamp . '"'; ZurmoRedBean::exec($sql); return true; }
public function testSaveAllMetadata() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $this->assertTrue(ContactsModule::loadStartingData()); $messageLogger = new MessageLogger(); InstallUtil::autoBuildDatabase($messageLogger, true); chdir(COMMON_ROOT . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'commands'); $command = "php zurmocTest.php manageMetadata super saveAllMetadata"; if (!IS_WINNT) { $command .= ' 2>&1'; } exec($command, $output); // Check if data are saved for some specific View $moduleMetadata = ZurmoRedBean::getRow("SELECT * FROM globalmetadata WHERE classname='NotesModule'"); $this->assertTrue($moduleMetadata['id'] > 0); $this->assertTrue(strlen($moduleMetadata['serializedmetadata']) > 0); // Check if data are saved for some specific View $modelMetadata = ZurmoRedBean::getRow("SELECT * FROM globalmetadata WHERE classname='Note'"); $this->assertTrue($modelMetadata['id'] > 0); $this->assertTrue(strlen($modelMetadata['serializedmetadata']) > 0); // Check if data are saved for some specific View $viewMetadata = ZurmoRedBean::getRow("SELECT * FROM globalmetadata WHERE classname='ContactsListView'"); $this->assertTrue($viewMetadata['id'] > 0); $this->assertTrue(strlen($viewMetadata['serializedmetadata']) > 0); }
/** * @return array */ protected function makeCombinedData() { $combinedRows = array(); //todo: should fix and get proper table name of attribute instead of passing in item $groupBy = $this->resolveGroupBy('EmailMessage', 'sentDateTime'); $beginDateTime = DateTimeUtil::convertDateIntoTimeZoneAdjustedDateTimeBeginningOfDay($this->beginDate); $endDateTime = DateTimeUtil::convertDateIntoTimeZoneAdjustedDateTimeEndOfDay($this->endDate); if ($this->marketingList == null) { $searchAttributeData = static::makeCampaignsSearchAttributeData('createdDateTime', $beginDateTime, $endDateTime, $this->campaign); $sql = static::makeCampaignsSqlQuery($searchAttributeData, $groupBy); $rows = ZurmoRedBean::getAll($sql); foreach ($rows as $row) { $this->addNewRowToCombinedRows($row, $combinedRows); } } if ($this->campaign == null) { $searchAttributeData = static::makeAutorespondersSearchAttributeData('createdDateTime', $beginDateTime, $endDateTime, $this->marketingList); $sql = static::makeAutorespondersSqlQuery($searchAttributeData, $groupBy); $rows = ZurmoRedBean::getAll($sql); foreach ($rows as $row) { $this->addNewRowToCombinedRows($row, $combinedRows); } } return $combinedRows; }
public function testRun() { //Create 2 jobLogs, and set one with a date over a week ago (8 days ago) for the endDateTime $eightDaysAgoTimestamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 60 * 60 * 24 * 8); $jobLog = new JobLog(); $jobLog->type = 'Monitor'; $jobLog->startDateTime = $eightDaysAgoTimestamp; $jobLog->endDateTime = $eightDaysAgoTimestamp; $jobLog->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR; $jobLog->isProcessed = false; $jobLog->save(); $jobLog2 = new JobLog(); $jobLog2->type = 'ImportCleanup'; $jobLog2->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); $jobLog2->endDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); $jobLog2->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR; $jobLog2->isProcessed = false; $jobLog2->save(); $sql = 'select count(*) count from item'; $row = ZurmoRedBean::getRow($sql); $this->assertEquals(4, $row['count']); $job = new JobLogCleanupJob(); $this->assertTrue($job->run()); $jobLogs = JobLog::getAll(); $this->assertEquals(1, count($jobLogs)); $this->assertEquals($jobLog2->id, $jobLogs[0]->id); $sql = 'select count(*) count from item'; $row = ZurmoRedBean::getRow($sql); $this->assertEquals(3, $row['count']); }
public function testProperlyDeletingActivityItems() { Yii::app()->user->userModel = User::getByUsername('super'); $count = ZurmoRedBean::getRow('select count(*) count from activity_item'); $this->assertEquals(0, $count['count']); $account = AccountTestHelper::createAccountByNameForOwner('anAccount', Yii::app()->user->userModel); $deleted = $account->delete(); $this->assertTrue($deleted); $count = ZurmoRedBean::getRow('select count(*) count from activity_item'); $this->assertEquals(0, $count['count']); $account2 = AccountTestHelper::createAccountByNameForOwner('anAccount2', Yii::app()->user->userModel); $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('anOpp', Yii::app()->user->userModel); $task = TaskTestHelper::createTaskWithOwnerAndRelatedAccount('aTask', Yii::app()->user->userModel, $account2); $task->activityItems->add($opportunity); $this->assertTrue($task->save()); $taskId = $task->id; $task->forget(); RedBeansCache::forgetAll(); $count = ZurmoRedBean::getRow('select count(*) count from activity_item'); $this->assertEquals(2, $count['count']); $deleted = $account2->delete(); $this->assertTrue($deleted); $account2->forget(); $count = ZurmoRedBean::getRow('select count(*) count from activity_item'); $this->assertEquals(1, $count['count']); RedBeansCache::forgetAll(); //Make sure things render ok even with the account deleted. $content = ActivitiesUtil::renderSummaryContent(Task::getById($taskId), 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL, 'HomeModule'); }
/** * Given a model and external system id, update the external system id in the database for that model * @param object $model * @param string $externalSystemId */ public static function updateByModel(RedBeanModel $model, $externalSystemId) { assert('$externalSystemId == null || is_string($externalSystemId)'); $columnName = self::EXTERNAL_SYSTEM_ID_COLUMN_NAME; $tableName = $model::getTableName(); static::addExternalIdColumnIfMissing($tableName); ZurmoRedBean::exec("update " . $tableName . " set {$columnName} = '" . $externalSystemId . "' where id = " . $model->id); }
public static function getUserExternalSystemIds() { $columnName = ExternalSystemIdUtil::EXTERNAL_SYSTEM_ID_COLUMN_NAME; $userTableName = User::getTableName(); ExternalSystemIdUtil::addExternalIdColumnIfMissing($userTableName); $sql = 'select ' . $columnName . ' from ' . $userTableName; return ZurmoRedBean::getCol($sql); }
/** * Given a event, perform the deletion of conversationItems related to the event sender. * @param CEvent $event */ public function deleteConversationItems(CEvent $event) { $model = $event->sender; assert('$model instanceof Item'); $itemId = $model->getClassId('Item'); $sql = 'DELETE from conversation_item where item_id = ' . $itemId; ZurmoRedBean::exec($sql); }
public static function cacheEntry($identifier, $entry) { assert('is_string($entry) || is_numeric($entry)'); parent::cacheEntry($identifier, $entry); if (static::supportsAndAllowsDatabaseCaching()) { ZurmoRedBean::exec("insert into actual_rights_cache\n (identifier, entry) values ('" . $identifier . "', '" . $entry . "') on duplicate key\n update entry = " . $entry); } }
/** * @return int */ public function calculateTotalItemCount() { $selectQueryAdapter = new RedBeanModelSelectQueryAdapter(); $sql = $this->makeSqlQueryForFetchingTotalItemCount($selectQueryAdapter); $rows = ZurmoRedBean::getAll($sql); $count = count($rows); return $count; }
public static function findGameTableRowsThatAreDuplicatedByPersonKey($tableName) { assert('is_string($tableName)'); // Begin Not Coding Standard $sql = "SELECT count(*) as count, person_item_id " . "FROM `" . $tableName . "` " . "GROUP BY person_item_id having count(person_item_id) > 1"; // End Not Coding Standard return ZurmoRedBean::getAll($sql); }
public static function addTransactionResolvedForOptimization($gamePoint, $value) { $transaction = new GamePointTransaction(); $transaction->value = $value; $transaction->unrestrictedSave(); $tableName = GamePointTransaction::getTableName(); $sql = "UPDATE {$tableName} SET gamepoint_id = '" . $gamePoint->id . "'\n WHERE id = '" . $transaction->id . "'"; ZurmoRedBean::exec($sql); }
public static function getKeys(RedBean_OODBBean $bean, $typeName, $name = null) { $fieldName = self::getLinkField($typeName, $name); $id = (int) $bean->{$fieldName}; $columnPrefix = self::resolveColumnPrefix($name); $columnName = $columnPrefix . $bean->getMeta("type") . '_id'; $ids = ZurmoRedBean::getCol("select id from {$typeName} where " . $columnName . " = {$bean->id}"); return $ids; }
public static function isCategoryInUseById($categoryId) { $categories = Category::getById($categoryId); $rows = ZurmoRedBean::getAll('SELECT * FROM customfieldvalue WHERE multiplevaluescustomfield_id IN (SELECT category_multiplevaluescustomfield_id FROM costbook) AND VALUE="' . $categories->name . '"'); if (count($rows) > 0) { return true; } else { return false; } }
protected function validJoinHelper($modelClassName, $attributeName, $relatedAttributeName) { $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => $attributeName, 'relatedAttributeName' => $relatedAttributeName, 'operatorType' => OperatorRules::TYPE_IS_NOT_NULL, 'value' => null)); $searchAttributeData['structure'] = '1'; $searchAttributeDataAndClassNames = array(array($modelClassName => $searchAttributeData)); $sql = RedBeanModelsDataProvider::makeUnionSql($searchAttributeDataAndClassNames, null, true); $result = ZurmoRedBean::GetAll($sql); $this->assertTrue(is_array($result)); }
/** * Given a event, perform the deletion of conversationItems related to the event sender. * @param CEvent $event */ public function deletePersonsOrAccountsItems(CEvent $event) { $model = $event->sender; assert('$model instanceof Item'); $itemId = $model->getClassId('Item'); $sql = 'DELETE from emailmessagerecipient_item where item_id = ' . $itemId; ZurmoRedBean::exec($sql); $sql = 'DELETE from emailmessagesender_item where item_id = ' . $itemId; ZurmoRedBean::exec($sql); }
public static function isUnitofmeasureInUseById($unitofmeasureId) { $unitofmeasures = Unitofmeasure::getById($unitofmeasureId); $rows = ZurmoRedBean::getAll('SELECT * FROM customfield WHERE id IN (SELECT unitofmeasure_customfield_id FROM costbook) AND VALUE="' . $unitofmeasures->name . '"'); if (count($rows) > 0) { return true; } else { return false; } }
public static function getByName($name) { assert('is_string($name)'); assert('$name != ""'); $bean = ZurmoRedBean::findOne('a', "name = :name ", array(':name' => $name)); assert('$bean === false || $bean instanceof RedBean_OODBBean'); if ($bean === false) { throw new NotFoundException(); } return self::makeModel($bean); }
/** * Get by specifying a class name and user. The class name is unique * and the data is saved in such a way that only one record will be * created per class name / user combination. * @see GlobalMetadata */ public static function getByClassNameAndUser($className, User $user) { assert('is_string($className)'); assert('$className != ""'); $bean = ZurmoRedBean::findOne('perusermetadata', "className = '{$className}' and _user_id = {$user->id}"); assert('$bean === false || $bean instanceof RedBean_OODBBean'); if ($bean === false) { throw new NotFoundException(); } return self::makeModel($bean); }
/** * Get by specifying a class name. The class name is unique * and so one object will be returned. */ public static function getByClassName($className) { assert('is_string($className)'); assert('$className != ""'); $bean = ZurmoRedBean::findOne('globalmetadata', "className = '{$className}'"); assert('$bean === false || $bean instanceof RedBean_OODBBean'); if ($bean === false) { throw new NotFoundException(); } return self::makeModel($bean); }
public function getChartData() { $customFieldData = CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName('Opportunity', 'stage'); $labels = CustomFieldDataUtil::getDataIndexedByDataAndTranslatedLabelsByLanguage($customFieldData, Yii::app()->language); $sql = static::makeChartSqlQuery(); $rows = ZurmoRedBean::getAll($sql); $chartData = array(); foreach ($rows as $row) { $chartData[] = array('value' => $this->resolveCurrencyValueConversionRateForCurrentUserForDisplay($row['amount']), 'displayLabel' => static::resolveLabelByValueAndLabels($row['stage'], $labels)); } return $chartData; }
public static function getAddProductSearchData($category, $costOfGoods) { $allAssemblySql = 'SELECT A.*, D.value AS UnitOfMeasure,B.value AS Category FROM costbook A LEFT JOIN customfieldvalue AS B ON B.multiplevaluescustomfield_id=A.category_multiplevaluescustomfield_id LEFT JOIN customfield AS C ON C.id =A.costofgoodssold_customfield_id LEFT JOIN customfield AS D ON A.unitofmeasure_customfield_id =D.id WHERE IF("ALL"="' . $category . '",TRUE,B.VALUE="' . $category . '") AND IF("ALL"="' . $costOfGoods . '",TRUE,C.VALUE="' . $costOfGoods . '")'; return ZurmoRedBean::getAll($allAssemblySql); }
public function getChartData() { $sql = static::makeSqlQuery(static::makeSearchAttributeData($this->autoresponder)); $row = ZurmoRedBean::getRow($sql); $data = static::resolveChartDataBaseGroupElements(); foreach ($data as $index => $notUsed) { if ($row[$index] != null) { $data[$index] = $row[$index]; } } return $data; }
public static function getByName($name) { assert('is_string($name)'); assert('$name != ""'); $bean = ZurmoRedBean::findOne('testselfrelatingmodel', "name = :name ", array(':name' => $name)); assert('$bean === false || $bean instanceof RedBean_OODBBean'); if ($bean === false) { if ($name == Group::EVERYONE_GROUP_NAME) { return self::createEveryoneGroup(); } throw new NotFoundException(); } return self::makeModel($bean); }
public function testRun() { $quote = DatabaseCompatibilityUtil::getQuote(); //Create 2 export items, and set one with a date over a week ago (8 days ago) for the modifiedDateTime $exportItem = new ExportItem(); $exportItem->isCompleted = 0; $exportItem->exportFileType = 'csv'; $exportItem->exportFileName = 'test'; $exportItem->modelClassName = 'Account'; $exportItem->serializedData = serialize(array('test', 'test2')); $this->assertTrue($exportItem->save()); $fileContent = new FileContent(); $fileContent->content = 'test'; $exportFileModel = new ExportFileModel(); $exportFileModel->fileContent = $fileContent; $exportFileModel->name = $exportItem->exportFileName . ".csv"; $exportFileModel->type = 'application/octet-stream'; $exportFileModel->size = strlen($fileContent->content); $this->assertTrue($exportFileModel->save()); $exportFileModel1Id = $exportFileModel->id; $exportItem->exportFileModel = $exportFileModel; $this->assertTrue($exportItem->save()); $modifiedDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 60 * 60 * 24 * 8); $sql = "Update item set modifieddatetime = '" . $modifiedDateTime . "' where id = " . $exportItem->getClassId('Item'); ZurmoRedBean::exec($sql); // Second exportItem, that shouldn't be deleted. $exportItem2 = new ExportItem(); $exportItem2->isCompleted = 0; $exportItem2->exportFileType = 'csv'; $exportItem2->exportFileName = 'test'; $exportItem2->modelClassName = 'Account'; $exportItem2->serializedData = serialize(array('test', 'test2')); $this->assertTrue($exportItem2->save()); $fileContent2 = new FileContent(); $fileContent2->content = 'test'; $exportFileModel2 = new ExportFileModel(); $exportFileModel2->fileContent = $fileContent2; $exportFileModel2->name = $exportItem->exportFileName . ".csv"; $exportFileModel2->type = 'application/octet-stream'; $exportFileModel2->size = strlen($fileContent->content); $this->assertTrue($exportFileModel2->save()); $exportFileModel2Id = $exportFileModel2->id; $exportItem2->exportFileModel = $exportFileModel2; $this->assertTrue($exportItem2->save()); $job = new ExportCleanupJob(); $this->assertTrue($job->run()); $exportItems = ExportItem::getAll(); $this->assertEquals(1, count($exportItems)); $this->assertEquals($exportItem2->id, $exportItems[0]->id); }