public function executeAddSeries(sfWebRequest $request) { try { $q = new Series(); $q->setSeriesName($request->getParameter('series_name')); $q->setBrandId($request->getParameter('brand_id')); $q->save(); $this->res = "Series Added!"; } catch (Exception $exc) { $this->res = $exc->getMessage(); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Series(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Series'])) { $model->attributes = $_POST['Series']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * Store a newly created resource in storage. * POST /series * * @return Response */ public function store() { $path = public_path() . '/uploads'; // $seriesTitle = Input::get('SeriesTitle'); $seriesDescription = Input::get('SeriesDesc'); $episodeTitle = Input::get('EpisodeTitle'); $episodeDesc = Input::get('EpisodeDesc'); $seriesType = Input::get('EpisodeType'); $episodeFile = Input::file('EpisodeFile'); $file = []; foreach ($episodeFile as $key => $value) { # code... $file[] = $value->getClientOriginalName(); $value->move($path, $value->getClientOriginalName()); } $tmp = array('epsTitle' => $episodeTitle, 'EpsDescription' => $episodeDesc, 'filename' => $file); $keys = array_keys($tmp); $iteration = count($tmp[$keys[0]]); $eps = []; for ($i = 0; $i < $iteration; $i++) { $data = array(); foreach ($tmp as $key => $value) { # code... $data[$key] = $value[$i]; // $data['file'] = $value->getClientOriginalName(); } $eps[] = array_merge($data); } // echo "<pre>"; // var_dump($eps); // echo "</pre>"; // Create Series $series = new Series(); $series->title = strtolower($seriesTitle); $series->description = strtolower($seriesTitle); $series->type = $seriesType; $series->user_id = Auth::id(); $series->category_id = 1; $series->save(); // //Create Document $input = array(); foreach ($eps as $key => $value) { # code... $input[] = new Documents(['title' => $value['epsTitle'], 'description' => $value['EpsDescription'], 'path' => $path . '/' . $value['filename']]); } $ser = Series::find($series->id); $ser->document()->saveMany($input); return Redirect::to('home'); }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aSeries !== null) { if ($this->aSeries->isModified() || $this->aSeries->isNew()) { $affectedRows += $this->aSeries->save($con); } $this->setSeries($this->aSeries); } if ($this->aReview !== null) { if ($this->aReview->isModified() || $this->aReview->isNew()) { $affectedRows += $this->aReview->save($con); } $this->setReview($this->aReview); } if ($this->aScore !== null) { if ($this->aScore->isModified() || $this->aScore->isNew()) { $affectedRows += $this->aScore->save($con); } $this->setScore($this->aScore); } if ($this->isNew()) { $this->modifiedColumns[] = ModelPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = ModelPeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += ModelPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collConfigs !== null) { foreach ($this->collConfigs as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collReviews !== null) { foreach ($this->collReviews as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collScores !== null) { foreach ($this->collScores as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collUserMetas !== null) { foreach ($this->collUserMetas as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
public function execute($request) { //get params $this->brand = $this->getRequestParameter('brand'); $this->series = $this->getRequestParameter('series'); $this->model = $this->getRequestParameter('model'); $this->configId = $this->getRequestParameter('config_id'); //get image files $this->mainImage = $this->getRequest()->getFiles('main_image'); $this->otherImages = $this->getRequest()->getFiles('other_images'); //print_r($this->otherImages); //exit (); //load/create series and model if (SeriesPeer::isNew($this->series)) { //create new series $seriesObj = new Series(); $seriesObj->setSeriesName($this->series); $seriesObj->setBrandId($this->brand); $seriesObj->save(); //create new model $modelObj = new Model(); $modelObj->setModelName($this->model); $modelObj->setSeries($seriesObj); $modelObj->save(); } else { //load series object $seriesObj = SeriesPeer::getSeriesByName($this->series); if (ModelPeer::isNew($this->model)) { //create new model $modelObj = new Model(); $modelObj->setModelName($this->model); $modelObj->setSeries($seriesObj); $modelObj->save(); } else { $modelObj = ModelPeer::getModelByName($this->model); } } ////////////////////// if (($this->isNew = $this->getRequestParameter('is_new')) == 'true') { //create new config $config = new Config(); $config->setConfigName($this->getRequestParameter('name')); $config->setModel($modelObj); $config->save(); //load config fields $configFields = ConfigFieldPeer::doSelect(new Criteria()); foreach ($configFields as $configField) { //get param if ($this->hasRequestParameter("field_" . $configField->getId())) { //if (strlen($this->getRequestParameter("field_".$configField->getId())) > 0 ) //{ $fieldValue = new FieldValue(); $fieldValue->setConfig($config); $fieldValue->setFieldId($configField->getId()); $fieldValue->setValue($this->getRequestParameter("field_" . $configField->getId())); $fieldValue->save(); //} } } } else { //load config $config = ConfigPeer::retrieveByPK($this->configId); //$config->setConfigName($this->getRequestParameter('name')); $config->setModel($modelObj); $config->save(); //load config fields $configFields = ConfigFieldPeer::doSelect(new Criteria()); foreach ($configFields as $configField) { //get param if ($this->hasRequestParameter("field_" . $configField->getId())) { //if (strlen($this->getRequestParameter("field_".$configField->getId())) > 0 ) //{ $fieldValue = FieldValuePeer::getFieldValue($configField->getId(), $config->getId()); $fieldValue->setValue($this->getRequestParameter("field_" . $configField->getId())); $fieldValue->save(); //} } } } //save main image MediaPeer::saveMedia($this->mainImage, $modelObj->getId(), MediaPeer::IMAGE, 'Model', true); //save other images foreach ($this->otherImages as $image) { MediaPeer::saveMedia($image, $modelObj->getId(), MediaPeer::IMAGE, 'Model', false); } if (($saveAndNew = $this->getRequestParameter('save_and_new')) == 'true') { $this->redirect('config/newconfig'); } else { $this->redirect('config/editconfig?id=' . $config->getId()); } }
/** * Execute the console command. * * @return mixed */ public function fire() { $dryRunOpt = $this->option('dry-run'); if ($dryRunOpt === true) { $dryRun = true; } elseif ($dryRunOpt === 'true') { $dryRun = true; } elseif ($dryRunOpt === 'false') { $dryRun = false; } else { $this->error('Invalid value for --dry-run'); return; } $sourceDirectories = array('/Manga/_Autouploads/AutoUploaded from Assorted Sources'); $movedFiles = array(); // Loop through each auto uploads parent folder foreach ($sourceDirectories as $sourceDirectory) { $sourcePath = Path::fromRelative($sourceDirectory); if (!$sourcePath->exists()) { $this->error('Source path does not exist: ' . $sourceDirectory); continue; } // Loop through each series dir in the auto uploads folder $sourceChildren = $sourcePath->getChildren(); foreach ($sourceChildren as $sourceChild) { $sourceName = $sourceChild->getFilename(); // Look for matching path records by series name $matchedRecords = PathRecord::join('series', 'series.id', '=', 'path_records.series_id')->join('facet_series', 'facet_series.series_id', '=', 'series.id')->join('facets', 'facets.id', '=', 'facet_series.facet_id')->where('facet_series.type', '=', 'title')->where('facets.name', '=', $sourceName)->get(); // Found a match if (count($matchedRecords) === 1) { $matchedRecord = $matchedRecords->first(); $matchedPath = $matchedRecord->getPath(); $seriesChildren = $sourceChild->getChildren(); foreach ($seriesChildren as $seriesChild) { if ($seriesChild->isDir()) { $this->error('ERROR: Sub-directory in source series: ' . $seriesChild->getPathName()); continue; } $srcFile = $seriesChild->getPathName(); $dstFile = $matchedPath->getPathName() . '/' . $seriesChild->getFilename(); if (file_exists($dstFile)) { if (filesize($srcFile) === filesize($dstFile) && md5_file($srcFile) === md5_file($dstFile)) { $dstFile = Path::fromRelative('/Admin cleanup')->getPathName() . '/' . $seriesChild->getFilename(); } else { $this->error('ERROR: Destination file already exists: ' . $dstFile); continue; } } $movedFiles[] = array('src' => $srcFile, 'dst' => $dstFile); $this->info($srcFile . ' -> ' . $dstFile); } } else { $row = DB::connection('mangaupdates')->table('namelist')->where('name', '=', $sourceName)->orWhere('fsSafeName', '=', $sourceName)->first(); $seriesId = null; if ($row) { $series = Series::where('mu_id', '=', $row->mu_id)->first(); if (!$series) { $series = new Series(); $series->mu_id = $row->mu_id; $series->save(); } $seriesId = $series->id; } $bucket = '# - F'; $chr = strtoupper($sourceName[0]); if ($chr >= 'N' && $chr <= 'Z') { $bucket = 'N - Z'; } elseif ($chr >= 'G' && $chr <= 'M') { $bucket = 'G - M'; } $dstSeries = Path::fromRelative('/Manga/' . $bucket)->getPathName() . '/' . $sourceName; if (file_exists($dstSeries)) { $seriesChildren = $sourceChild->getChildren(); foreach ($seriesChildren as $seriesChild) { if ($seriesChild->isDir()) { $this->error('ERROR: Sub-directory in source series: ' . $seriesChild->getPathName()); continue; } $srcFile = $seriesChild->getPathName(); $dstFile = $dstSeries . '/' . $seriesChild->getFilename(); if (file_exists($dstFile)) { if (filesize($srcFile) === filesize($dstFile) && md5_file($srcFile) === md5_file($dstFile)) { $dstFile = Path::fromRelative('/Admin cleanup')->getPathName() . '/' . $seriesChild->getFilename(); } else { $this->error('ERROR: Destination file already exists: ' . $dstFile); continue; } } $movedFiles[] = array('src' => $srcFile, 'dst' => $dstFile); $this->info($srcFile . ' -> ' . $dstFile); } } else { $movedFiles[] = array('src' => $sourceChild->getPathName(), 'dst' => $dstSeries); $this->info($sourceChild->getPathName() . ' -> ' . $dstSeries); } } } } if (!$dryRun) { foreach ($movedFiles as $move) { try { if (is_file($move['src'])) { $dir = dirname($move['src']); if (!is_dir($dir)) { mkdir($dir, 0777, true); } } rename($move['src'], $move['dst']); } catch (ErrorException $exception) { $this->error('ERROR: rename() failed: ' . $seriesChild->getPathName() . ' -> ' . $dstFile . ' ' . $exception->getMessage()); } } } file_put_contents(storage_path() . '/logs/merge-auto-uploads-' . date('Y-m-d-H-i-s'), serialize($movedFiles)); if (!$dryRun) { // Delete empty source folders foreach ($sourceDirectories as $sourceDirectory) { $sourcePath = Path::fromRelative($sourceDirectory); if (!$sourcePath->exists()) { $this->error('Source path does not exist: ' . $sourceDirectory); continue; } $sourceChildren = $sourcePath->getChildren(); foreach ($sourceChildren as $sourceChild) { if (count($sourceChild->getChildren()) === 0) { rmdir($sourceChild->getPathName()); } } } } }
function handleActions() { global $hasError; global $errormsg; if (!isset($_POST['series'])) { return; } $seriesname = $_POST['series']; $series = new Series($seriesname); if (!$series) { return; } if (!$series->authCheck(Player::loginName())) { return; } if ($_POST['action'] == "Update Series") { $newactive = $_POST['isactive']; $newtime = $_POST['hour']; $newday = $_POST['start_day']; $prereg = 0; if (isset($_POST['preregdefault'])) { $prereg = $_POST['preregdefault']; } $series = new Series($seriesname); if ($series->authCheck(Player::loginName())) { $series->active = $newactive; $series->start_time = $newtime . ":00:00"; $series->start_day = $newday; $series->prereg_default = $prereg; $series->save(); } } else { if ($_POST['action'] == "Change Logo") { if ($_FILES['logo']['size'] > 0) { $file = $_FILES['logo']; $name = $file['name']; $tmp = $file['tmp_name']; $size = $file['size']; $type = $file['type']; $series->setLogo($tmp, $type, $size); } } else { if ($_POST['action'] == "Update Organizers") { if (isset($_POST['delstewards'])) { $removals = $_POST['delstewards']; foreach ($removals as $deadsteward) { $series->removeSteward($deadsteward); } } if (!isset($_POST['addsteward'])) { return; } $addition = $_POST['addsteward']; $addplayer = Player::findByName($addition); if ($addplayer == NULL) { $hasError = true; $errormsg .= "Can't add {$addition} to stewards, they don't exist!"; return; } if ($addplayer->verified == 0 && Player::getSessionPlayer()->super == 0) { $hasError = true; $errormsg .= "Can't add {$addplayer->name} to stewards, they aren't a verified user!"; return; } $series->addSteward($addplayer->name); } else { if ($_POST['action'] == "Update Points Rules") { $new_rules = $_POST['new_rules']; $series->setSeasonRules($_POST['season'], $new_rules); } } } } }