public function actionRemovePlaylistFromChannel()
 {
     if (isset($_POST['channelType']) && isset($_POST['plId']) && isset($_POST['pointId'])) {
         $channelType = intval($_POST['channelType']);
         $plId = intval($_POST['plId']);
         $pointId = intval($_POST['pointId']);
         if (PlaylistToPoint::model()->deleteAllByAttributes(array('id_point' => $pointId, 'id_playlist' => $plId, 'channel_type' => $channelType))) {
             echo json_encode(array('status' => 'ok'));
         } else {
             echo json_encode(array('status' => 'err', 'error' => 'Error during PlaylistToPoint model deleting'));
         }
     } else {
         echo json_encode(array('status' => 'err', 'error' => 'Incorrect POST data during PlaylistToPoint model deleting'));
     }
 }
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     $model = $this->loadModel($id);
     $files = trim($model->files);
     $model->delete();
     if (isset($files) && $files != '') {
         $filesArr = explode(",", $files);
         $this->DeleteALLFilesFromPlaylist($id, $filesArr);
     }
     PlaylistToPoint::model()->deleteAllByAttributes(['id_playlist' => $id]);
     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
     if (!isset($_GET['ajax'])) {
         $this->redirect(array('playlists/index'), array('model' => $model));
     }
 }
예제 #3
0
 public function PrepareFilesForSync($id)
 {
     $model = self::model()->findByPk($id);
     $pointDir = "spool/points/" . $model->id;
     //remove dir if exist
     if (file_exists($pointDir)) {
         try {
             $this->DeleteDir($pointDir);
         } catch (Exception $e) {
             error_log("Unlink failed. Exception - " . json_encode($e) . "Dir - " . $pointDir);
         }
     }
     $avaliablePlaylists = PlaylistToPoint::model()->findAllByAttributes(['id_point' => $id]);
     $connection = Yii::app()->db;
     foreach ($avaliablePlaylists as $playlistToPoint) {
         $pl = $playlistToPoint->playlist;
         $channelDir = $pointDir . "/" . $playlistToPoint->channel_type;
         $channelFullDir = $this->PrepareSpoolPath($channelDir);
         $plFiles = explode(",", $pl->files);
         foreach ($plFiles as $fileId) {
             if ($fileId != '') {
                 $connection->active = true;
                 $sql = "SELECT `name`, `path` FROM `file` WHERE `id` = " . $fileId . ";";
                 $command = $connection->createCommand($sql);
                 $dataReader = $command->query();
                 if (($row = $dataReader->read()) !== false) {
                     $path = $row['path'];
                     $fileName = $row['name'];
                     $symlinkPath = $channelFullDir . $fileName;
                     if (!file_exists($symlinkPath)) {
                         if (defined('SYMLINK')) {
                             symlink($path, $symlinkPath);
                         } else {
                             copy($path, $symlinkPath);
                         }
                     }
                 }
                 $connection->active = false;
             }
         }
     }
 }