From 9e81d4b6cadde78eba46d76948472e367af1caf5 Mon Sep 17 00:00:00 2001
From: Rasmus Fuhse <fuhse@data-quest.de>
Date: Tue, 20 Jun 2017 13:36:20 +0200
Subject: [PATCH] re #76

---
 assets/pluginmarket.less             |  3 ++
 controllers/myplugins.php            |  6 ++++
 controllers/presenting.php           | 15 +++++---
 migrations/07_add_pluginname.php     | 52 ++++++++++++++--------------
 migrations/08_deprecated_plugins.php | 15 ++++++++
 views/myplugins/edit.php             |  7 ++++
 views/presenting/_plugin_short.php   |  2 +-
 7 files changed, 68 insertions(+), 32 deletions(-)
 create mode 100644 migrations/08_deprecated_plugins.php

diff --git a/assets/pluginmarket.less b/assets/pluginmarket.less
index 43cc227..5c1b643 100755
--- a/assets/pluginmarket.less
+++ b/assets/pluginmarket.less
@@ -79,6 +79,9 @@
                 #gradient .vertical(fadeout(#fff, 100%), #fff);
             }
         }
+        &.deprecated {
+            opacity: 0.5;
+        }
     }
 
     &.new > article {
diff --git a/controllers/myplugins.php b/controllers/myplugins.php
index 0dab406..f8d1784 100755
--- a/controllers/myplugins.php
+++ b/controllers/myplugins.php
@@ -96,6 +96,12 @@ class MypluginsController extends MarketController
             if (!isset($data["donationsaccepted"])) {
                 $data['donationsaccepted'] = 0;
             }
+            if (!$this->marketplugin->isRootable() && isset($data['deprecated'])) {
+                unset($data['deprecated']);
+            }
+            if ($this->marketplugin->isRootable() && !isset($data['deprecated'])) {
+                $data['deprecated'] = 0;
+            }
             $this->marketplugin->setData($data);
             if ($this->marketplugin->isNew() && (MarketPlugin::findOneByPluginname($this->marketplugin->pluginname) || !strlen(trim($this->marketplugin->pluginname)))) {
                 PageLayout::postError(_("Ein Plugin mit diesem Namen ist schon im Marktplatz vorhanden!"));
diff --git a/controllers/presenting.php b/controllers/presenting.php
index 93ce294..798f389 100755
--- a/controllers/presenting.php
+++ b/controllers/presenting.php
@@ -87,9 +87,9 @@ class PresentingController extends MarketController
             }
         }
 
-        $this->plugins = MarketPlugin::findBySQL("publiclyvisible = 1 AND approved = 1 ORDER BY RAND() LIMIT 3");
+        $this->plugins = MarketPlugin::findBySQL("publiclyvisible = 1 AND approved = 1 AND deprecated = 0 ORDER BY RAND() LIMIT 3");
 
-        $this->latest_plugins = MarketPlugin::findBySQL("publiclyvisible = 1 AND approved = 1 ORDER BY mkdate DESC LIMIT 5");
+        $this->latest_plugins = MarketPlugin::findBySQL("publiclyvisible = 1 AND approved = 1 AND deprecated = 0 ORDER BY mkdate DESC LIMIT 5");
 
         $best = DBManager::get()->prepare("
             SELECT pluginmarket_plugins.*
@@ -97,6 +97,7 @@ class PresentingController extends MarketController
                 LEFT JOIN pluginmarket_reviews ON (pluginmarket_plugins.plugin_id = pluginmarket_reviews.plugin_id)
             WHERE publiclyvisible = 1
                 AND approved = 1
+                AND deprecated = 0
             GROUP BY pluginmarket_plugins.plugin_id
             ORDER BY pluginmarket_plugins.rating DESC, MAX(pluginmarket_reviews.chdate) DESC
             LIMIT 6
@@ -123,7 +124,7 @@ class PresentingController extends MarketController
                     )
                     AND publiclyvisible = 1
                     AND approved = 1
-                ORDER BY (IF(name LIKE :likesearch, 6, 0) + MATCH (short_description, description) AGAINST (:search)),name ", array(
+                ORDER BY deprecated ASC, (IF(name LIKE :likesearch, 6, 0) + MATCH (short_description, description) AGAINST (:search)), name ", array(
                     'likesearch' => "%".Request::get("search")."%",
                     'search' => Request::get("search")
                 )
@@ -136,7 +137,7 @@ class PresentingController extends MarketController
                 WHERE pluginmarket_tags.tag = :tag
                     AND pluginmarket_plugins.approved = 1
                     AND pluginmarket_plugins.publiclyvisible = 1
-                ORDER BY name
+                ORDER BY deprecated ASC, name ASC
             ");
             $statement->execute(array('tag' => Request::get("tag")));
             $plugin_data = $statement->fetchAll(PDO::FETCH_ASSOC);
@@ -148,7 +149,7 @@ class PresentingController extends MarketController
                 $this->plugins[] = $plugin;
             }
         } else {
-            $this->plugins = MarketPlugin::findBySQL("publiclyvisible = 1 AND approved = 1 ORDER BY name ASC");
+            $this->plugins = MarketPlugin::findBySQL("publiclyvisible = 1 AND approved = 1 AND deprecated = 0 ORDER BY name ASC");
         }
 
         // Filter version
@@ -179,6 +180,10 @@ class PresentingController extends MarketController
         $this->marketplugin['rating'] = $this->marketplugin->calculateRating();
         $this->marketplugin->store();
 
+        if ($this->marketplugin['deprecated']) {
+            PageLayout::postInfo(_("Dieses Plugin gilt als veraltet."));
+        }
+
         // Add actions widget
         $sidebar = Sidebar::Get();
         $actions = new ActionsWidget();
diff --git a/migrations/07_add_pluginname.php b/migrations/07_add_pluginname.php
index 268b525..4d1255b 100644
--- a/migrations/07_add_pluginname.php
+++ b/migrations/07_add_pluginname.php
@@ -1,39 +1,39 @@
 <?php
 class AddPluginname extends Migration {
 
-public function up() {
+    public function up() {
 
-    DBManager::get()->exec("
-    ALTER TABLE `pluginmarket_plugins` CHANGE `pluginclassname` `pluginname` VARCHAR(64) NOT NULL
-    ");
-    SimpleORMap::expireTableScheme();
-    foreach (MarketPlugin::findBySQL("1") as $plugin) {
-        if ($plugin->releases->count()) {
-            $pluginnames = array_count_values(array_filter($plugin->releases->getPluginName()));
-            arsort($pluginnames);
-            $pluginname = key($pluginnames);
-            if ($pluginname) {
-                $plugin->pluginname = $pluginname;
+        DBManager::get()->exec("
+            ALTER TABLE `pluginmarket_plugins` CHANGE `pluginclassname` `pluginname` VARCHAR(64) NOT NULL
+        ");
+        SimpleORMap::expireTableScheme();
+        foreach (MarketPlugin::findBySQL("1") as $plugin) {
+            if ($plugin->releases->count()) {
+                $pluginnames = array_count_values(array_filter($plugin->releases->getPluginName()));
+                arsort($pluginnames);
+                $pluginname = key($pluginnames);
+                if ($pluginname) {
+                    $plugin->pluginname = $pluginname;
 
-                $plugin->releases->each(function ($one) use ($pluginname) {
-                    if ($one->getPluginName() != $pluginname) {
-                        $one->delete();
-                    }
-                });
+                    $plugin->releases->each(function ($one) use ($pluginname) {
+                        if ($one->getPluginName() != $pluginname) {
+                            $one->delete();
+                        }
+                    });
+                } else {
+                    $plugin->name .= " (no pluginname)";
+                    $plugin->releases->delete();
+                    $plugin->approved = 0;
+                }
             } else {
-                $plugin->name .= " (no pluginname)";
-                $plugin->releases->delete();
+                $plugin->name .= " (no release)";
                 $plugin->approved = 0;
             }
-        } else {
-            $plugin->name .= " (no release)";
-            $plugin->approved = 0;
+            $plugin->store();
         }
-        $plugin->store();
     }
-}
 
-public function down() {
-}
+    public function down() {
+    }
 
 }
\ No newline at end of file
diff --git a/migrations/08_deprecated_plugins.php b/migrations/08_deprecated_plugins.php
new file mode 100644
index 0000000..fdbda54
--- /dev/null
+++ b/migrations/08_deprecated_plugins.php
@@ -0,0 +1,15 @@
+<?php
+class DeprecatedPlugins extends Migration {
+
+    public function up() {
+
+        DBManager::get()->exec("
+            ALTER TABLE `pluginmarket_plugins` ADD COLUMN `deprecated` TINYINT(1) NOT NULL DEFAULT '0' AFTER `rating`
+        ");
+        SimpleORMap::expireTableScheme();
+    }
+
+    public function down() {
+    }
+
+}
\ No newline at end of file
diff --git a/views/myplugins/edit.php b/views/myplugins/edit.php
index 67af538..412961f 100755
--- a/views/myplugins/edit.php
+++ b/views/myplugins/edit.php
@@ -59,6 +59,13 @@
             <input type="checkbox" name="data[donationsaccepted]" value="1"<?= $marketplugin->isNew() || $marketplugin['donationsaccepted'] ? " checked" : "" ?>>
         </label>
 
+        <? if ($marketplugin->isRootable()) : ?>
+            <label>
+                <?= _("Plugin veraltet") ?>
+                <input type="checkbox" name="data[deprecated]" value="1"<?= $marketplugin['deprecated'] ? " checked" : "" ?>>
+            </label>
+        <? endif ?>
+
 
     </fieldset>
 
diff --git a/views/presenting/_plugin_short.php b/views/presenting/_plugin_short.php
index bf452b4..c9b36f3 100755
--- a/views/presenting/_plugin_short.php
+++ b/views/presenting/_plugin_short.php
@@ -1,4 +1,4 @@
-<article class="contentbox">
+<article class="contentbox<?= $marketplugin['deprecated'] ? " deprecated" : "" ?>">
     <a href="<?= $controller->url_for('presenting/details/' . $marketplugin->getId()) ?>">
         <header>
             <h1><?= htmlReady($marketplugin['name']) ?></h1>
-- 
GitLab